From a4152239f6aa235a5f5cc40d15dc732bd364e948 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 24 Jan 2019 18:39:07 -0800 Subject: [PATCH] remove sms permissions from play store variant and from a new debug variant so that can be tested. Add explanation to be shown users who try to use the now-unavailable features. --- xwords4/android/app/build.gradle | 39 +++++++++++++- .../android/app/src/main/AndroidManifest.xml | 2 - .../java/org/eehouse/android/xw4/Perms23.java | 52 +++++++++++++++++-- .../app/src/main/res/values/common_rsrc.xml | 1 + .../app/src/main/res/values/strings.xml | 8 +++ .../android/app/src/xw4d/AndroidManifest.xml | 3 ++ .../org/eehouse/android/xw4/CrashTrack.java | 1 + .../org/eehouse/android/xw4/FBMService.java | 1 + xwords4/android/jni/andutils.c | 2 +- xwords4/android/jni/xwjni.c | 2 +- xwords4/android/scripts/Variant.mk | 2 +- 11 files changed, 102 insertions(+), 11 deletions(-) create mode 120000 xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/CrashTrack.java create mode 120000 xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/FBMService.java diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle index d154eb972..8dfcb27bb 100644 --- a/xwords4/android/app/build.gradle +++ b/xwords4/android/app/build.gradle @@ -68,7 +68,7 @@ android { buildConfigField "String", "BUILD_INFO_NAME", "\"${BUILD_INFO_NAME}\"" buildConfigField "boolean", "IS_TAGGED_BUILD", "${CURTAG}" == '' ? "false" : "true" resValue "string", "invite_prefix", "/and/" - buildConfigField "String", "GCM_SENDER_ID", "\"\"" + buildConfigField "int[]", "SMS_BANNED_EXPL", "null" } xw4 { @@ -76,10 +76,12 @@ android { applicationId "org.eehouse.android.xw4" manifestPlaceholders = [ APP_ID: applicationId ] resValue "string", "app_name", "CrossWords" - resValue "string", "nbs_port", "3344" + resValue "string", "nbs_port", "0" buildConfigField "boolean", "WIDIR_ENABLED", "false" buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "false" buildConfigField "String", "VARIANT_NAME", "\"Google Play Store\"" + buildConfigField "int[]", "SMS_BANNED_EXPL", + "{R.string.key_notagain_sms_banned, R.string.sms_banned_expl}" } xw4fdroid { @@ -103,6 +105,19 @@ android { buildConfigField "String", "VARIANT_NAME", "\"Dev/Debug\"" } + xw4dNoSMS { + dimension "variant" + applicationId "org.eehouse.android.xw4dbg" + manifestPlaceholders = [ FABRIC_API_KEY: "$FABRIC_API_KEY", APP_ID: applicationId, ] + resValue "string", "app_name", "CrossDbg" + resValue "string", "nbs_port", "3345" + buildConfigField "boolean", "WIDIR_ENABLED", "true" + buildConfigField "boolean", "RELAYINVITE_SUPPORTED", "true" + buildConfigField "String", "VARIANT_NAME", "\"Dev/Debug sans SMS\"" + buildConfigField "int[]", "SMS_BANNED_EXPL", + "{R.string.key_notagain_sms_banned, R.string.sms_banned_expl}" + } + // WARNING: "all" breaks things. Seems to be a keyword. Need // to figure out how to express include-all-abis // all { @@ -173,6 +188,14 @@ android { jniLibs.srcDir "../libs-xw4dDebug" } } + xw4dNoSMS { + release { + jniLibs.srcDir "../libs-xw4dNoSMSRelease" + } + debug { + jniLibs.srcDir "../libs-xw4dNoSMSDebug" + } + } xw4fdroid { release { jniLibs.srcDir "../libs-xw4fdroidRelease" @@ -213,6 +236,9 @@ dependencies { xw4dImplementation('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') { // rm-for-fdroid transitive = true; // rm-for-fdroid } // rm-for-fdroid + xw4dNoSMSImplementation('com.crashlytics.sdk.android:crashlytics:2.6.3@aar') { // rm-for-fdroid + transitive = true; // rm-for-fdroid + } // rm-for-fdroid implementation 'com.google.firebase:firebase-messaging:17.3.4' // rm-for-fdroid implementation 'com.google.firebase:firebase-core:16.0.6' // rm-for-fdroid @@ -294,6 +320,15 @@ afterEvaluate { "src/xw4d/res/values/strings.xml" } preBuild.dependsOn copyStringsTask + + String copyStringsTaskNoSMS = "copyStringsXw4DNoSMS" + task "$copyStringsTaskNoSMS"(type: Exec) { + workingDir './' + environment.put('APPNAME', 'CrossDbg') + commandLine 'make', '-f', '../scripts/Variant.mk', + "src/xw4dNoSMS/res/values/strings.xml" + } + preBuild.dependsOn copyStringsTaskNoSMS } task makeBuildAssets() { diff --git a/xwords4/android/app/src/main/AndroidManifest.xml b/xwords4/android/app/src/main/AndroidManifest.xml index 0e9e03dd0..41c34dec1 100644 --- a/xwords4/android/app/src/main/AndroidManifest.xml +++ b/xwords4/android/app/src/main/AndroidManifest.xml @@ -18,8 +18,6 @@ - - diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java index 43ec939ea..442da6147 100644 --- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java +++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/Perms23.java @@ -47,14 +47,21 @@ public class Perms23 { public static enum Perm { READ_PHONE_STATE(Manifest.permission.READ_PHONE_STATE), STORAGE(Manifest.permission.WRITE_EXTERNAL_STORAGE), - SEND_SMS(Manifest.permission.SEND_SMS), - RECEIVE_SMS(Manifest.permission.RECEIVE_SMS), + SEND_SMS(Manifest.permission.SEND_SMS, BuildConfig.SMS_BANNED_EXPL), + RECEIVE_SMS(Manifest.permission.RECEIVE_SMS, BuildConfig.SMS_BANNED_EXPL), READ_CONTACTS(Manifest.permission.READ_CONTACTS); private String m_str; - private Perm(String str) { m_str = str; } + private int[] m_expl; + private Perm(String str) { this(str, null); } + private Perm(String str, int[] bannedExpl) { + m_str = str; + m_expl = bannedExpl; + } public String getString() { return m_str; } + public boolean isBanned() { return m_expl != null; } + public int[] getExpl() { Assert.assertTrue(isBanned()); return m_expl; } public static Perm getFor( String str ) { Perm result = null; for ( Perm one : Perm.values() ) { @@ -184,7 +191,27 @@ public class Perms23 { private void doIt( boolean showRationale ) { - Builder builder = new Builder( m_perms ); + Set validPerms = new HashSet<>(); + Set bannedPerms = new HashSet<>(); + for ( Perm perm : m_perms ) { + if ( perm.isBanned() ) { + bannedPerms.add( perm ); + } else { + validPerms.add( perm ); + } + } + + if ( 0 < validPerms.size() ) { + doItAsk( validPerms, showRationale ); + } + if ( 0 < bannedPerms.size() ) { + doItFail( bannedPerms ); + } + } + + private void doItAsk( Set perms, boolean showRationale ) + { + Builder builder = new Builder( perms ); if ( showRationale && null != m_rationaleMsg ) { builder.setOnShowRationale( new OnShowRationale() { @Override @@ -222,6 +249,23 @@ public class Perms23 { } ); } + // Cons up a call with a "no" answer, and post it. + private void doItFail( Set bannedPerms ) + { + int resID = 0; + + final Perm[] perms = bannedPerms.toArray( new Perm[bannedPerms.size()] ); + int[] expls = perms[0].getExpl(); + m_delegate.makeNotAgainBuilder(expls[1], expls[0]).show(); + + m_delegate.post( new Runnable() { + @Override + public void run() { + m_delegate.onNegButton( m_action, perms ); + } + } ); + } + // Post this in case we're called from inside dialog dismiss // code. Better to unwind the stack... private void handleButton( final boolean positive ) diff --git a/xwords4/android/app/src/main/res/values/common_rsrc.xml b/xwords4/android/app/src/main/res/values/common_rsrc.xml index 419decc77..e1a4b34e2 100644 --- a/xwords4/android/app/src/main/res/values/common_rsrc.xml +++ b/xwords4/android/app/src/main/res/values/common_rsrc.xml @@ -136,6 +136,7 @@ key_invite_multi key_notagain_rematch_two_only key_notagain_dfltname + key_notagain_sms_banned key_na_comms_bt key_na_comms_p2p key_na_comms_sms diff --git a/xwords4/android/app/src/main/res/values/strings.xml b/xwords4/android/app/src/main/res/values/strings.xml index fcdfc4e70..b1baaacbc 100644 --- a/xwords4/android/app/src/main/res/values/strings.xml +++ b/xwords4/android/app/src/main/res/values/strings.xml @@ -2768,4 +2768,12 @@ • Launch CrossWords on the other device\n • If all else fails, reboot this device\n + + Play-via-SMS requires Permissions + that most Android apps are no longer allowed to request -- as a + condition of being listed on the Google Play Store. Thus + play-via-SMS no longer works on copies of CrossWords obtained + through the Play Store (as this one was.) If you miss this feature, + please check http://eehouse.org/sms.html for updates on the + situation. diff --git a/xwords4/android/app/src/xw4d/AndroidManifest.xml b/xwords4/android/app/src/xw4d/AndroidManifest.xml index 105eee0e9..439ac4305 100644 --- a/xwords4/android/app/src/xw4d/AndroidManifest.xml +++ b/xwords4/android/app/src/xw4d/AndroidManifest.xml @@ -6,6 +6,9 @@ + + + diff --git a/xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/CrashTrack.java b/xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/CrashTrack.java new file mode 120000 index 000000000..bd7d4edbf --- /dev/null +++ b/xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/CrashTrack.java @@ -0,0 +1 @@ +../../../../../../xw4d/java/org/eehouse/android/xw4/CrashTrack.java \ No newline at end of file diff --git a/xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/FBMService.java b/xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/FBMService.java new file mode 120000 index 000000000..c61b45e58 --- /dev/null +++ b/xwords4/android/app/src/xw4dNoSMS/java/org/eehouse/android/xw4/FBMService.java @@ -0,0 +1 @@ +../../../../../../xw4/java/org/eehouse/android/xw4/FBMService.java \ No newline at end of file diff --git a/xwords4/android/jni/andutils.c b/xwords4/android/jni/andutils.c index 1df894fbe..1df845e25 100644 --- a/xwords4/android/jni/andutils.c +++ b/xwords4/android/jni/andutils.c @@ -756,7 +756,7 @@ android_debugf( const char* format, ... ) (void)__android_log_write( ANDROID_LOG_DEBUG, # if defined VARIANT_xw4 || defined VARIANT_xw4fdroid "xw4" -# elif defined VARIANT_xw4d +# elif defined VARIANT_xw4d || defined VARIANT_xw4dNoSMS "x4bg" # endif , buf ); diff --git a/xwords4/android/jni/xwjni.c b/xwords4/android/jni/xwjni.c index b6ff65792..52de70eca 100644 --- a/xwords4/android/jni/xwjni.c +++ b/xwords4/android/jni/xwjni.c @@ -683,7 +683,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getUUID #ifdef XWFEATURE_BLUETOOTH # if defined VARIANT_xw4 || defined VARIANT_xw4fdroid (*env)->NewStringUTF( env, XW_BT_UUID ) -# elif defined VARIANT_xw4d +# elif defined VARIANT_xw4d || defined VARIANT_xw4dNoSMS (*env)->NewStringUTF( env, XW_BT_UUID_DBG ) # endif #else diff --git a/xwords4/android/scripts/Variant.mk b/xwords4/android/scripts/Variant.mk index c75de5a6a..cee03ccc7 100644 --- a/xwords4/android/scripts/Variant.mk +++ b/xwords4/android/scripts/Variant.mk @@ -1,6 +1,6 @@ # -*- mode: Makefile; -*- -src/xw4d/res/values/strings.xml: src/main/res/values/strings.xml +src/%/res/values/strings.xml: src/main/res/values/strings.xml @mkdir -p $(shell dirname $@) @sed \ -e "s,CrossWords,$(APPNAME),g" \