From da68e7baa9aee4b7f259bbec1c6c140767ee5e09 Mon Sep 17 00:00:00 2001 From: OsmoTACDB Project Date: Thu, 28 Apr 2016 21:41:38 +0200 Subject: first version of our AWESOME app --- app/.gitignore | 1 + app/build.gradle | 27 +++ app/proguard-rules.pro | 17 ++ .../osmocom/tacdatabaseclient/ApplicationTest.java | 13 ++ app/src/main/AndroidManifest.xml | 26 +++ app/src/main/ic_launcher-web.png | Bin 0 -> 14097 bytes .../osmocom/tacdatabaseclient/MainActivity.java | 230 +++++++++++++++++++++ app/src/main/res/drawable/osmocom_logo.png | Bin 0 -> 122758 bytes app/src/main/res/layout/activity_main.xml | 48 +++++ app/src/main/res/layout/content_main.xml | 54 +++++ app/src/main/res/menu/menu_main.xml | 4 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 9345 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 4598 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 15069 bytes app/src/main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 23517 bytes app/src/main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 8538 bytes app/src/main/res/values-v21/styles.xml | 9 + app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/dimens.xml | 6 + app/src/main/res/values/strings.xml | 23 +++ app/src/main/res/values/styles.xml | 20 ++ .../osmocom/tacdatabaseclient/ExampleUnitTest.java | 15 ++ build.gradle | 23 +++ gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 ++++++++++++++ gradlew.bat | 90 ++++++++ settings.gradle | 1 + 30 files changed, 803 insertions(+) create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/org/osmocom/tacdatabaseclient/ApplicationTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/ic_launcher-web.png create mode 100644 app/src/main/java/org/osmocom/tacdatabaseclient/MainActivity.java create mode 100644 app/src/main/res/drawable/osmocom_logo.png create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/content_main.xml create mode 100644 app/src/main/res/menu/menu_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values-v21/styles.xml create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/org/osmocom/tacdatabaseclient/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..77193cb --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "19.1.0" + + defaultConfig { + applicationId "org.osmocom.tacdatabaseclient" + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:design:23.1.1' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..a00f1b5 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/nion/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/org/osmocom/tacdatabaseclient/ApplicationTest.java b/app/src/androidTest/java/org/osmocom/tacdatabaseclient/ApplicationTest.java new file mode 100644 index 0000000..ca23617 --- /dev/null +++ b/app/src/androidTest/java/org/osmocom/tacdatabaseclient/ApplicationTest.java @@ -0,0 +1,13 @@ +package org.osmocom.tacdatabaseclient; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d9bc6eb --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/ic_launcher-web.png b/app/src/main/ic_launcher-web.png new file mode 100644 index 0000000..1fb93b8 Binary files /dev/null and b/app/src/main/ic_launcher-web.png differ diff --git a/app/src/main/java/org/osmocom/tacdatabaseclient/MainActivity.java b/app/src/main/java/org/osmocom/tacdatabaseclient/MainActivity.java new file mode 100644 index 0000000..03b084b --- /dev/null +++ b/app/src/main/java/org/osmocom/tacdatabaseclient/MainActivity.java @@ -0,0 +1,230 @@ +package org.osmocom.tacdatabaseclient; + +import android.Manifest; +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.os.Build; +import android.os.Bundle; +import android.os.StrictMode; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.View; +import android.telephony.TelephonyManager; +import android.content.Context; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLEncoder; + +public class MainActivity extends AppCompatActivity { + private static final int MY_PERMISSIONS_REQUEST_READ_PHONE_STATE = 225; + private static final int MY_PERMISSIONS_INTERNET = 223; + + private static final String TAG = "osmoTAC"; + private String imei, model, manufacturer, tac; + private long app_status; + + // UI elements + private FloatingActionButton button_send; + private Button button_allow; + private Toolbar toolbar; + private TextView text_send_data; + private TextView text_send_status; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // needed for getDeviceInfo() + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); + + // UI elements + toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + TextView text_footer = (TextView) findViewById(R.id.url_text); + text_send_data = (TextView) findViewById(R.id.send_data); + text_send_status = (TextView) findViewById(R.id.send_status); + button_allow = (Button) findViewById(R.id.button_allow); + button_send = (FloatingActionButton) findViewById(R.id.fab); + button_send.setEnabled(false); + + if (getStatus(this) > 0) { + TextView header = (TextView) findViewById(R.id.blabla); + header.setText(R.string.already_done); + button_allow.setText(getText(R.string.uninstall)); + + button_allow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + uninstallApp(); + } + }); + } else { + button_allow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + requestPermissions(); + } + }); + } + + button_send.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + sendInformation(); + } + }); + + + } + + @Override + public void onRequestPermissionsResult(int requestCode, + String permissions[], int[] grantResults) { + switch (requestCode) { + case MY_PERMISSIONS_REQUEST_READ_PHONE_STATE: { + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + + getDeviceInformation(); + + } else { + text_send_data.setText("permissions denied!"); + } + return; + } + } + } + + protected void requestPermissions() { + Log.d(TAG, "requesting permissions"); + + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.READ_PHONE_STATE) + != PackageManager.PERMISSION_GRANTED) { + + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.READ_PHONE_STATE}, + MY_PERMISSIONS_REQUEST_READ_PHONE_STATE); + } else { + getDeviceInformation(); + } + + if (ContextCompat.checkSelfPermission(this, + Manifest.permission.INTERNET) + != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.INTERNET}, + MY_PERMISSIONS_INTERNET); + } + } + + protected void getDeviceInformation() { + TelephonyManager mngr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); + imei = mngr.getDeviceId(); + + if (imei == null) { + text_send_data.setText(R.string.tac_error); + return; + } + + model = Build.MODEL; + manufacturer = Build.MANUFACTURER; + tac = imei.substring(0, 8); + + button_send.setEnabled(true); + button_allow.setEnabled(false); + + String inf = String.format("This is the data that we send:\n\n\t\tTAC: %s\n\t\tModel: %s" + + "\n\t\tManufacturer: %s", tac, model, manufacturer); + text_send_data.setText(inf); + + Log.d(TAG, Build.HARDWARE); + Log.d(TAG, Build.MODEL + "" + Build.MANUFACTURER); + Log.d(TAG, tac); + } + + protected void sendInformation() { + URL url; + HttpURLConnection urlConnection; + String reqURL = getString(R.string.submit_resource); + int statusCode; + + text_send_status.setText(R.string.send_status); + + try { + reqURL += "?tac=" + URLEncoder.encode(tac, "utf-8"); + reqURL += "&model=" + URLEncoder.encode(model, "utf-8"); + reqURL += "&manufacturer=" + URLEncoder.encode(manufacturer, "utf-8"); + + url = new URL(reqURL); + + urlConnection = (HttpURLConnection) url.openConnection(); + urlConnection.disconnect(); + statusCode = urlConnection.getResponseCode(); + text_send_status.append(getString(R.string.send_done)); + + Log.d(TAG, "status: " + statusCode); + if (urlConnection != null) { + if (statusCode == 404) { + setStatus(this); + button_send.setEnabled(false); + showToast(getString(R.string.thanks_msg)); + Log.d(TAG, "app_status:" + String.valueOf(app_status)); + } + } + } catch (UnsupportedEncodingException e) { + Log.d(TAG, "unsupported encoding"); + showToast(getString(R.string.error_string)); + return; + } catch (MalformedURLException me) { + Log.d(TAG, "malformed URL!?"); + showToast(getString(R.string.error_string)); + return; + } catch (IOException e) { + text_send_status.setText(getString(R.string.send_error)); + showToast(getString(R.string.error_string)); + } + + } + + private void showToast(String toast) { + Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_SHORT).show(); + } + + private void setStatus(Activity activity) { + SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putInt(getString(R.string.app_status), 1); + editor.commit(); + } + + private long getStatus(Activity activity) { + SharedPreferences sharedPref = activity.getPreferences(Context.MODE_PRIVATE); + return sharedPref.getInt(getString(R.string.app_status), 0); + } + + private void uninstallApp() { + Uri packageUri = Uri.parse(getString(R.string.package_uri)); + Intent uninstallIntent = + new Intent(Intent.ACTION_UNINSTALL_PACKAGE, packageUri); + startActivity(uninstallIntent); + } + +} diff --git a/app/src/main/res/drawable/osmocom_logo.png b/app/src/main/res/drawable/osmocom_logo.png new file mode 100644 index 0000000..e6c0a26 Binary files /dev/null and b/app/src/main/res/drawable/osmocom_logo.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..c85f12f --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 0000000..0aa53c7 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,54 @@ + + + + + +