From 26cd72d78c5d053618a5d9ea2959a7914a7347c9 Mon Sep 17 00:00:00 2001 From: wkouki Date: Wed, 12 Jul 2023 15:32:11 +0900 Subject: [PATCH 01/58] revert build gradle copyright year --- niap-cc/Permissions/Companion/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/niap-cc/Permissions/Companion/README.md b/niap-cc/Permissions/Companion/README.md index 7445c57..142b8db 100644 --- a/niap-cc/Permissions/Companion/README.md +++ b/niap-cc/Permissions/Companion/README.md @@ -1,4 +1,4 @@ -# Permission Test Tool Companion +# Permission Test Tool Companion This sample app is a tool which aids OEMs in testing their devices for evaluation of the Common Criteria certificate through [NIAP](https://www.niap-ccevs.org/). From 2c3cbe038aa4492ca293b0f4daae3406335d2cdc Mon Sep 17 00:00:00 2001 From: wkouki Date: Wed, 12 Jul 2023 15:33:22 +0900 Subject: [PATCH 02/58] checkout as new branch for new vesion --- niap-cc/Permissions/Companion/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/niap-cc/Permissions/Companion/README.md b/niap-cc/Permissions/Companion/README.md index 142b8db..bdae738 100644 --- a/niap-cc/Permissions/Companion/README.md +++ b/niap-cc/Permissions/Companion/README.md @@ -1,4 +1,4 @@ -# Permission Test Tool Companion +# Permission Test Tool Companion This sample app is a tool which aids OEMs in testing their devices for evaluation of the Common Criteria certificate through [NIAP](https://www.niap-ccevs.org/). From 8d04f7cbd5af4fc34fddf3f25e0d178234f7af35 Mon Sep 17 00:00:00 2001 From: wkouki Date: Fri, 14 Jul 2023 17:08:02 +0900 Subject: [PATCH 03/58] Companion : - Mend broken custom plugins - Update gradle version - Change sdk version - Append new service registration corresponding to bind_* permissions --- niap-cc/Permissions/Companion/.gitignore | 3 + .../Permissions/Companion/app/build.gradle | 23 +-- .../app/src/main/AndroidManifest.xml | 33 ++++- .../permissions/companion/MainActivity.java | 20 ++- .../TestBindCallStreamingServiceService.java | 52 +++++++ ...tBindCredentialProviderServiceService.java | 52 +++++++ ...BindFieldClassificationServiceService.java | 52 +++++++ ...oteLockscreenValidationServiceService.java | 52 +++++++ ...estBindSatelliteGatewayServiceService.java | 52 +++++++ .../TestBindSatelliteServiceService.java | 52 +++++++ ...indVisualQueryDetectionServiceService.java | 52 +++++++ ...TestBindWearableSensingServiceService.java | 52 +++++++ niap-cc/Permissions/Companion/build.gradle | 136 ------------------ .../Permissions/Companion/build.gradle.kts | 135 +++++++++++++++++ .../Companion/buildSrc/build.gradle.kts | 8 ++ .../build/kotlin/buildSrcjar-classes.txt | 0 .../local-state/build-history.bin | Bin 0 -> 31 bytes .../buildSrc/build/tmp/jar/MANIFEST.MF | 2 + .../Permissions/Companion/gradle.properties | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 3 +- niap-cc/Permissions/Companion/settings.gradle | 2 - .../Permissions/Companion/settings.gradle.kts | 2 + 22 files changed, 630 insertions(+), 158 deletions(-) create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCallStreamingServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCredentialProviderServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindFieldClassificationServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindRemoteLockscreenValidationServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteGatewayServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindVisualQueryDetectionServiceService.java create mode 100644 niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindWearableSensingServiceService.java delete mode 100644 niap-cc/Permissions/Companion/build.gradle create mode 100644 niap-cc/Permissions/Companion/build.gradle.kts create mode 100644 niap-cc/Permissions/Companion/buildSrc/build.gradle.kts create mode 100644 niap-cc/Permissions/Companion/buildSrc/build/kotlin/buildSrcjar-classes.txt create mode 100644 niap-cc/Permissions/Companion/buildSrc/build/kotlin/compileKotlin/local-state/build-history.bin create mode 100644 niap-cc/Permissions/Companion/buildSrc/build/tmp/jar/MANIFEST.MF delete mode 100644 niap-cc/Permissions/Companion/settings.gradle create mode 100644 niap-cc/Permissions/Companion/settings.gradle.kts diff --git a/niap-cc/Permissions/Companion/.gitignore b/niap-cc/Permissions/Companion/.gitignore index 5ca1e65..ae585a9 100644 --- a/niap-cc/Permissions/Companion/.gitignore +++ b/niap-cc/Permissions/Companion/.gitignore @@ -40,3 +40,6 @@ app/build /security +buildSrc/.gradle +builSrc/build +.gradle/ \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/build.gradle b/niap-cc/Permissions/Companion/app/build.gradle index c97ea6c..7499b88 100644 --- a/niap-cc/Permissions/Companion/app/build.gradle +++ b/niap-cc/Permissions/Companion/app/build.gradle @@ -17,7 +17,7 @@ apply plugin: 'com.android.application' def applicationName = 'Companion' android { - compileSdkVersion 33 + compileSdk 34 signingConfigs { // TODO : // Prepare your own companion.jks and put it into @@ -34,7 +34,8 @@ android { defaultConfig { applicationId "com.android.certifications.niap.permissions.companion" minSdkVersion 28 - targetSdkVersion 33 + //noinspection EditedTargetSdkVersion,OldTargetApi + targetSdkVersion 34 versionCode 1 versionName "1.0" signingConfig signingConfigs.companion @@ -65,19 +66,23 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - lintOptions { + namespace 'com.android.certifications.niap.permissions.companion' + buildFeatures { + aidl true + } + lint { abortOnError false } - namespace 'com.android.certifications.niap.permissions.companion' } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'com.google.android.material:material:1.1.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - testImplementation 'junit:junit:4.12' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'com.google.android.gms:play-services-location:21.0.1' + testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation 'com.google.android.gms:play-services-location:17.0.0' + } diff --git a/niap-cc/Permissions/Companion/app/src/main/AndroidManifest.xml b/niap-cc/Permissions/Companion/app/src/main/AndroidManifest.xml index c37ed65..23d8dd5 100644 --- a/niap-cc/Permissions/Companion/app/src/main/AndroidManifest.xml +++ b/niap-cc/Permissions/Companion/app/src/main/AndroidManifest.xml @@ -14,16 +14,19 @@ See the License for the specific language governing permissions and limitations under the License. --> - + + + - + + + + + + + + + diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java index d286a55..8e352d4 100644 --- a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java @@ -17,7 +17,7 @@ package com.android.certifications.niap.permissions.companion; import static android.app.PendingIntent.FLAG_IMMUTABLE; -import static android.app.PendingIntent.FLAG_MUTABLE; +import static android.app.PendingIntent.FLAG_NO_CREATE; import android.Manifest; import android.app.Activity; @@ -45,6 +45,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; @@ -124,6 +125,9 @@ public void onClick(View view) { /** * {@link AsyncTask} used to drive the setup for the permission tests. + * + * Fix: We shouldn't use AsyncTask anymore ... refine it later + * */ private class SetupTestsAsyncTask extends AsyncTask { @Override @@ -179,7 +183,7 @@ private boolean verifyLocationSettings() { // location request. If the cause of the exception is a ResolveableApiException then // the resolution from the exception can be used to prompt the user to configure GMS. Throwable exceptionCause = e.getCause(); - if (exceptionCause != null && exceptionCause instanceof ApiException) { + if (exceptionCause instanceof ApiException) { ApiException apiException = (ApiException) exceptionCause; switch (apiException.getStatusCode()) { case LocationSettingsStatusCodes @@ -261,9 +265,14 @@ public void onReceive(Context context, Intent intent) { } }; - registerReceiver(receiver, new IntentFilter(ACCESS_LOCATION_ACTION)); + int flags = ContextCompat.RECEIVER_NOT_EXPORTED;//RECEIVER_EXPORTED + ContextCompat.registerReceiver + (this, receiver, new IntentFilter(ACCESS_LOCATION_ACTION), flags); + //TODO: Bug? From U+ We can't create mutable Pending Intent directly ... + // We should investigate an alternative plan to verify the location service Intent intent = new Intent(ACCESS_LOCATION_ACTION); - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, FLAG_MUTABLE); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, + PendingIntent.FLAG_MUTABLE|FLAG_NO_CREATE); FusedLocationProviderClient locationClient = LocationServices.getFusedLocationProviderClient(this); try { @@ -274,7 +283,7 @@ public void onReceive(Context context, Intent intent) { } boolean locationReceived = false; try { - locationReceived = latch[0].await(60, TimeUnit.SECONDS); + locationReceived = latch[0].await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Log.e(TAG, "Caught an InterruptedException: ", e); } @@ -393,6 +402,7 @@ private void setupLocusTest() { @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + //super.onRequestPermissionsResult(requestCode, permissions, grantResults); boolean permissionGranted = true; for (int grantResult : grantResults) { if (grantResult != PackageManager.PERMISSION_GRANTED) { diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCallStreamingServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCallStreamingServiceService.java new file mode 100644 index 0000000..dfc71cb --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCallStreamingServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindCallStreamingServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindCallStreamingServiceService extends Service { + private static final String TAG = "TestBindCallStreamingServiceService"; + private TestBindCallStreamingServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindCallStreamingServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindCallStreamingServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindCallStreamingServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCredentialProviderServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCredentialProviderServiceService.java new file mode 100644 index 0000000..1fae63e --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindCredentialProviderServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindCredentialProviderServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindCredentialProviderServiceService extends Service { + private static final String TAG = "TestBindCredentialProviderServiceService"; + private TestBindCredentialProviderServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindCredentialProviderServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindCredentialProviderServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindCredentialProviderServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindFieldClassificationServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindFieldClassificationServiceService.java new file mode 100644 index 0000000..06fb62c --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindFieldClassificationServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindFieldClassificationServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindFieldClassificationServiceService extends Service { + private static final String TAG = "TestBindFieldClassificationServiceService"; + private TestBindFieldClassificationServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindFieldClassificationServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindFieldClassificationServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindFieldClassificationServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindRemoteLockscreenValidationServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindRemoteLockscreenValidationServiceService.java new file mode 100644 index 0000000..1af0943 --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindRemoteLockscreenValidationServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindRemoteLockscreenValidationServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindRemoteLockscreenValidationServiceService extends Service { + private static final String TAG = "TestBindRemoteLockscreenValidationServiceService"; + private TestBindRemoteLockscreenValidationServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindRemoteLockscreenValidationServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindRemoteLockscreenValidationServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindRemoteLockscreenValidationServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteGatewayServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteGatewayServiceService.java new file mode 100644 index 0000000..73fb98a --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteGatewayServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindSatelliteGatewayServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindSatelliteGatewayServiceService extends Service { + private static final String TAG = "TestBindSatelliteGatewayServiceService"; + private TestBindSatelliteGatewayServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindSatelliteGatewayServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindSatelliteGatewayServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindSatelliteGatewayServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteServiceService.java new file mode 100644 index 0000000..b99b2c7 --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindSatelliteServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindSatelliteServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindSatelliteServiceService extends Service { + private static final String TAG = "TestBindSatelliteServiceService"; + private TestBindSatelliteServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindSatelliteServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindSatelliteServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindSatelliteServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindVisualQueryDetectionServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindVisualQueryDetectionServiceService.java new file mode 100644 index 0000000..88e8d9b --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindVisualQueryDetectionServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindVisualQueryDetectionServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindVisualQueryDetectionServiceService extends Service { + private static final String TAG = "TestBindVisualQueryDetectionServiceService"; + private TestBindVisualQueryDetectionServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindVisualQueryDetectionServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindVisualQueryDetectionServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindVisualQueryDetectionServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindWearableSensingServiceService.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindWearableSensingServiceService.java new file mode 100644 index 0000000..7c5810f --- /dev/null +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/services/TestBindWearableSensingServiceService.java @@ -0,0 +1,52 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link TestBindWearableSensingServiceServiceImpl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class TestBindWearableSensingServiceService extends Service { + private static final String TAG = "TestBindWearableSensingServiceService"; + private TestBindWearableSensingServiceServiceImpl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new TestBindWearableSensingServiceServiceImpl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class TestBindWearableSensingServiceServiceImpl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "TestBindWearableSensingServiceServiceService"); + } + } +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/build.gradle b/niap-cc/Permissions/Companion/build.gradle deleted file mode 100644 index 0870170..0000000 --- a/niap-cc/Permissions/Companion/build.gradle +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -// Top-level build file where you can add configuration options common to all sub-projects/modules. -buildscript { - repositories { - google() - jcenter() - } - dependencies { - classpath 'com.android.tools.build:gradle:4.2.2' - classpath "com.google.guava:guava:24.1-jre" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files - } -} - -allprojects { - repositories { - google() - jcenter() - } -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -import static com.google.common.base.CaseFormat.* - -String.metaClass.caseFormat = { from, to -> - from.to( to, delegate ) -} - -//CodeGenerator -class Android13BindPlugin implements Plugin { - def PERMISSIONS=[ - 'BIND_ATTESTATION_VERIFICATION_SERVICE', - 'BIND_TRACE_REPORT_SERVICE', - 'BIND_GAME_SERVICE', - 'BIND_SELECTION_TOOLBAR_RENDER_SERVICE', - 'BIND_WALLPAPER_EFFECTS_GENERATION_SERVICE', - 'BIND_TV_INTERACTIVE_APP', - 'BIND_AMBIENT_CONTEXT_DETECTION_SERVICE'] - - - void apply(Project project) { - project.task('a13permissions') { - doLast { - def manifestTags = []; - for(pm in PERMISSIONS){ - def className = "Test"+pm.caseFormat( UPPER_UNDERSCORE, UPPER_CAMEL )+"Service" - def filePath = "${project.projectDir}/app/src/main/java/com/android/certifications/niap/permissions/companion/services/" - new File(filePath+className+".java"). - text = - "/*\n" + - " * Copyright 2022 The Android Open Source Project\n" + - " *\n" + - " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" + - " * you may not use this file except in compliance with the License.\n" + - " * You may obtain a copy of the License at\n" + - " *\n" + - " * http://www.apache.org/licenses/LICENSE-2.0\n" + - " *\n" + - " * Unless required by applicable law or agreed to in writing, software\n" + - " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" + - " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + - " * See the License for the specific language governing permissions and\n" + - " * limitations under the License.\n" + - " */\n"+ - "package com.android.certifications.niap.permissions.companion.services;\n" + - "\n" + - "import android.app.Service;\n" + - "import android.content.Intent;\n" + - "import android.os.IBinder;\n" + - "import android.util.Log;\n" + - "\n" + - "/**\n" + - " * Exported service used to test the "+pm+" permission.\n" + - " *\n" + - " * This service requires clients are granted the "+pm+"\n" + - " * permission to bind to it. The Permission Test Tool can attempt to bind to this service\n" + - " * and invoke the {@link "+className+"Impl#testMethod()} method\n" + - " * to verify that the platform properly enforces this permission requirement.\n" + - " */\n"+ - "public class "+className+" extends Service {\n" + - " private static final String TAG = \""+className+"\";\n" + - " private "+className+"Impl bindService;\n" + - "\n" + - " @Override\n" + - " public void onCreate() {\n" + - " super.onCreate();\n" + - " bindService = new "+className+"Impl();\n" + - " }\n" + - "\n" + - " @Override\n" + - " public IBinder onBind(Intent intent) {\n" + - " return bindService;\n" + - " }\n" + - "\n" + - " static class "+className+"Impl extends TestBindService.Stub {\n" + - " public void testMethod() {\n" + - " Log.d(TAG, \"The caller successfully invoked the test method on service \"\n" + - " + \""+className+"\");\n" + - " }\n" + - " }\n" + - "}" - - def tag = "" - manifestTags.push(tag); - } - - println manifestTags.join("\n"); - } - } - } -} - -apply plugin: Android13BindPlugin \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/build.gradle.kts b/niap-cc/Permissions/Companion/build.gradle.kts new file mode 100644 index 0000000..98f0622 --- /dev/null +++ b/niap-cc/Permissions/Companion/build.gradle.kts @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.gradle.api.* +import com.google.common.base.CaseFormat//Guava +import java.nio.file.Files + +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath("com.android.tools.build:gradle:8.0.2") + classpath("com.google.guava:guava:24.1-jre") + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +// Command to call this plugin +// ./gradlew bindServiceCodeGen +class BindServiceCodeGenPlugin:Plugin { + + val PERMISSIONS = arrayListOf( + "BIND_CALL_STREAMING_SERVICE", + "BIND_CREDENTIAL_PROVIDER_SERVICE", + "BIND_FIELD_CLASSIFICATION_SERVICE", + "BIND_REMOTE_LOCKSCREEN_VALIDATION_SERVICE", + "BIND_SATELLITE_GATEWAY_SERVICE", + "BIND_SATELLITE_SERVICE", + "BIND_VISUAL_QUERY_DETECTION_SERVICE", + "BIND_WEARABLE_SENSING_SERVICE" + ) + override fun apply(project:Project){ + project.task("bindServiceCodeGen"){ + doLast { + val manifestTags:MutableList = arrayListOf() + + for(pm in PERMISSIONS){ + val cased_pm = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, pm) + val className = "Test${cased_pm}Service" + val outPath = "${project.projectDir}/app/src/main/java/com/android/certifications/niap/permissions/companion/services/" + //println(outPath+className+".java") + val f = File(outPath+className+".java") + if(f.exists()) Files.delete(f.toPath()) + val generatedCode = """ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.certifications.niap.permissions.companion.services; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; +import android.util.Log; + +/** + * Exported service used to test the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE permission. + * + * This service requires clients are granted the BIND_AMBIENT_CONTEXT_DETECTION_SERVICE + * permission to bind to it. The Permission Test Tool can attempt to bind to this service + * and invoke the {@link ${className}Impl#testMethod()} method + * to verify that the platform properly enforces this permission requirement. + */ +public class $className extends Service { + private static final String TAG = "$className"; + private ${className}Impl bindService; + + @Override + public void onCreate() { + super.onCreate(); + bindService = new ${className}Impl(); + } + + @Override + public IBinder onBind(Intent intent) { + return bindService; + } + + static class ${className}Impl extends TestBindService.Stub { + public void testMethod() { + Log.d(TAG, "The caller successfully invoked the test method on service " + + "${className}Service"); + } + } +} """.trim() + f.writeText(generatedCode); + + val tag = """""".trimIndent() + + // + manifestTags.add(tag) + } + println(manifestTags.joinToString(separator = "\n")) + } + } + + } +} +apply() \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/buildSrc/build.gradle.kts b/niap-cc/Permissions/Companion/buildSrc/build.gradle.kts new file mode 100644 index 0000000..8d607fd --- /dev/null +++ b/niap-cc/Permissions/Companion/buildSrc/build.gradle.kts @@ -0,0 +1,8 @@ +import org.gradle.kotlin.dsl.`kotlin-dsl` + +repositories { + mavenCentral() +} +plugins { + `kotlin-dsl` +} \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/buildSrc/build/kotlin/buildSrcjar-classes.txt b/niap-cc/Permissions/Companion/buildSrc/build/kotlin/buildSrcjar-classes.txt new file mode 100644 index 0000000..e69de29 diff --git a/niap-cc/Permissions/Companion/buildSrc/build/kotlin/compileKotlin/local-state/build-history.bin b/niap-cc/Permissions/Companion/buildSrc/build/kotlin/compileKotlin/local-state/build-history.bin new file mode 100644 index 0000000000000000000000000000000000000000..c0e03058c543b66a94b23bac1a1b23b62147b144 GIT binary patch literal 31 ccmZ4UmVvcgk^ur385kHl{Uo!$Lir2~09!}|fdBvi literal 0 HcmV?d00001 diff --git a/niap-cc/Permissions/Companion/buildSrc/build/tmp/jar/MANIFEST.MF b/niap-cc/Permissions/Companion/buildSrc/build/tmp/jar/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/niap-cc/Permissions/Companion/buildSrc/build/tmp/jar/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/niap-cc/Permissions/Companion/gradle.properties b/niap-cc/Permissions/Companion/gradle.properties index c52ac9b..091e018 100644 --- a/niap-cc/Permissions/Companion/gradle.properties +++ b/niap-cc/Permissions/Companion/gradle.properties @@ -16,4 +16,7 @@ org.gradle.jvmargs=-Xmx2048m # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=true +android.defaults.buildfeatures.buildconfig=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/gradle/wrapper/gradle-wrapper.properties b/niap-cc/Permissions/Companion/gradle/wrapper/gradle-wrapper.properties index 2b228cc..da1db5f 100644 --- a/niap-cc/Permissions/Companion/gradle/wrapper/gradle-wrapper.properties +++ b/niap-cc/Permissions/Companion/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Jul 02 17:14:56 PDT 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip diff --git a/niap-cc/Permissions/Companion/settings.gradle b/niap-cc/Permissions/Companion/settings.gradle deleted file mode 100644 index 573abcb..0000000 --- a/niap-cc/Permissions/Companion/settings.gradle +++ /dev/null @@ -1,2 +0,0 @@ -include ':app' - diff --git a/niap-cc/Permissions/Companion/settings.gradle.kts b/niap-cc/Permissions/Companion/settings.gradle.kts new file mode 100644 index 0000000..99f836b --- /dev/null +++ b/niap-cc/Permissions/Companion/settings.gradle.kts @@ -0,0 +1,2 @@ +include (":app") + From 41ec85de77096a1c191b0f2fc9ab145c905e9f2e Mon Sep 17 00:00:00 2001 From: wkouki Date: Wed, 19 Jul 2023 11:35:47 +0900 Subject: [PATCH 04/58] Companion : - Enable to show the task status into UI --- niap-cc/Permissions/Companion/.gitignore | 3 +- .../permissions/companion/MainActivity.java | 120 ++++++++++++------ .../app/src/main/res/layout/activity_main.xml | 33 ++--- .../Permissions/Companion/build.gradle.kts | 4 +- 4 files changed, 104 insertions(+), 56 deletions(-) diff --git a/niap-cc/Permissions/Companion/.gitignore b/niap-cc/Permissions/Companion/.gitignore index ae585a9..df89f27 100644 --- a/niap-cc/Permissions/Companion/.gitignore +++ b/niap-cc/Permissions/Companion/.gitignore @@ -42,4 +42,5 @@ app/build buildSrc/.gradle builSrc/build -.gradle/ \ No newline at end of file +.gradle/ +.idea/ \ No newline at end of file diff --git a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java index 8e352d4..63c174a 100644 --- a/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java +++ b/niap-cc/Permissions/Companion/app/src/main/java/com/android/certifications/niap/permissions/companion/MainActivity.java @@ -40,7 +40,9 @@ import android.provider.MediaStore; import android.util.Log; import android.view.View; +import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.ListView; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; @@ -65,6 +67,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -84,7 +88,17 @@ public class MainActivity extends AppCompatActivity { Manifest.permission.ACCESS_FINE_LOCATION, }; - private TextView mStatusTextView; + private ListView mStatusListView; + static List mStatusData = new ArrayList(); + static ArrayAdapter mStatusAdapter; + + protected void setAdapters(){ + mStatusAdapter = new ArrayAdapter( + this, + android.R.layout.simple_list_item_1, + mStatusData); + mStatusListView.setAdapter(mStatusAdapter); + } private Button mSetupButton; private boolean mGmsAvailable; @@ -92,13 +106,42 @@ public class MainActivity extends AppCompatActivity { * Used to ensure the GMS location settings are configured as required for the location tests. */ private LocationRequest mLocationRequest; + private void logdebug(String text) + { + Log.d(TAG, text); + runOnUiThread(new Runnable() { + @Override + public void run() { + if(mStatusAdapter != null){ + mStatusAdapter.add("🟩"+text); + } + } + }); + } + private void logerror(String text) + { + Log.e(TAG, text); + runOnUiThread(new Runnable() { + @Override + public void run() { + if(mStatusAdapter != null){ + mStatusAdapter.add("🔴"+text); + + } + } + }); + + } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Log.d(TAG, "Running permission tester companion setup on build " + Build.FINGERPRINT); + mStatusListView = findViewById(R.id.statusTextView); + setAdapters(); + + logdebug("Running permission tester companion setup on build " + Build.FINGERPRINT); mGmsAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS; @@ -106,10 +149,9 @@ protected void onCreate(Bundle savedInstanceState) { mLocationRequest = LocationRequest.create().setPriority( LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY).setInterval(1000); } else { - Log.d(TAG, "GMS is not available on this device"); + logdebug( "GMS is not available on this device"); } - mStatusTextView = findViewById(R.id.statusTextView); mSetupButton = findViewById(R.id.setupButton); mSetupButton.setOnClickListener(new View.OnClickListener() { @Override @@ -120,7 +162,9 @@ public void onClick(View view) { long currTimeMs = System.currentTimeMillis(); final DropBoxManager db = (DropBoxManager) getApplicationContext().getSystemService(Context.DROPBOX_SERVICE); + logdebug("Put a data into the DropBox Manager"); db.addText("test-companion-tag","Companion:PEEK_DROPBOX_DATA test at :"+currTimeMs); + } /** @@ -132,7 +176,8 @@ public void onClick(View view) { private class SetupTestsAsyncTask extends AsyncTask { @Override protected void onPreExecute() { - mStatusTextView.setText(R.string.setup_in_progress); + //mStatusTextView.setText(R.string.setup_in_progress); + logdebug("Setup in progress"); mSetupButton.setEnabled(false); } @@ -155,9 +200,9 @@ protected Boolean doInBackground(Void... noParams) { @Override protected void onPostExecute(Boolean setupComplete) { if (!setupComplete) { - mStatusTextView.setText(R.string.setup_failed); + logerror("Setup failed"); } else { - mStatusTextView.setText(R.string.setup_complete); + logdebug("☑️Setup complete with no error"); } mSetupButton.setEnabled(true); } @@ -176,7 +221,7 @@ private boolean verifyLocationSettings() { this).checkLocationSettings(locationSettingsRequest); try { Tasks.await(result, 10, TimeUnit.SECONDS); - Log.d(TAG, "Location settings indicate location should be available"); + logdebug( "Location settings indicate location should be available"); return true; } catch (ExecutionException e) { // An ExecutionException indicates that GMS is not properly configured to support this @@ -195,31 +240,31 @@ private boolean verifyLocationSettings() { resolvableApiException.startResolutionForResult(this, REQUEST_LOCATION_SETTINGS); } catch (IntentSender.SendIntentException intentException) { - Log.d(TAG, + logerror( "Caught a SendIntentException attempting to launch the " + "Settings page"); } } else { - Log.d(TAG, + logerror( "Settings resolution is required to access location, but " + "Exception is not an instanceof " + "ResolvableApiException"); } break; case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE: - Log.d(TAG, + logerror( "Settings resolution is required to access location, but the " + "change is unavailable from this app"); break; default: - Log.d(TAG, "Received unknown status code " + apiException.getStatusCode() - + " from exception: ", e); + logerror("Received unknown status code " + apiException.getStatusCode() + + " from exception: "+e.getLocalizedMessage()); } } else { - Log.d(TAG, "Caught an ExecutionException verifying the location settings: ", e); + logerror( "Caught an ExecutionException verifying the location settings: "); } } catch (TimeoutException | InterruptedException e) { - Log.d(TAG, "An exception was caught verifying the location settings: ", e); + logerror( "An exception was caught verifying the location settings: "); } return false; } @@ -240,12 +285,12 @@ private boolean setupLocationTest() { if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { - Log.d(TAG, "Location permission has not been granted; prompting for it now"); + logerror( "Location permission has not been granted; prompting for it now"); ActivityCompat.requestPermissions(this, LOCATION_PERMISSIONS, REQUEST_LOCATION_PERMISSION); return false; } else { - Log.d(TAG, "ACCESS_FINE_LOCATION permission has been granted"); + logdebug( "ACCESS_FINE_LOCATION permission has been granted"); } BroadcastReceiver receiver = new BroadcastReceiver() { @@ -257,7 +302,7 @@ public void onReceive(Context context, Intent intent) { if (result != null) { Location location = result.getLastLocation(); if (location != null) { - Log.d(TAG, "Received a lat,long of " + location.getLatitude() + ", " + logdebug( "Received a lat,long of " + location.getLatitude() + ", " + location.getLongitude()); latch[0].countDown(); } @@ -278,19 +323,19 @@ public void onReceive(Context context, Intent intent) { try { locationClient.requestLocationUpdates(mLocationRequest, pendingIntent); } catch (SecurityException e) { - Log.e(TAG, "Caught a SecurityException requesting location updates: ", e); + logerror("Caught a SecurityException requesting location updates: "); return false; } boolean locationReceived = false; try { locationReceived = latch[0].await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { - Log.e(TAG, "Caught an InterruptedException: ", e); + logerror( "Caught an InterruptedException: "); } locationClient.removeLocationUpdates(pendingIntent); unregisterReceiver(receiver); if (!locationReceived) { - Log.d(TAG, "Location update not received within timeout window"); + logerror("Location update not received within timeout window"); } return locationReceived; } @@ -322,9 +367,10 @@ private boolean setupMediaLocationTest() { while (inputStream.read(bytes) != -1) { outputStream.write(bytes); } - Log.d(TAG, "Successfully wrote file to pictures directory"); + logdebug( "Successfully wrote file to pictures directory"); + } catch (IOException e) { - Log.e(TAG, "Caught an exception copying file:", e); + logerror("Caught an exception copying file:"); result = false; } photoContentValues.put(MediaStore.Images.Media.IS_PENDING, 0); @@ -346,9 +392,9 @@ private boolean setupMediaLocationTest() { while (inputStream.read(bytes) != -1) { outputStream.write(bytes); } - Log.d(TAG, "Successfully wrote file to Music directory"); + logdebug( "Successfully wrote file to Music directory"); } catch (IOException e) { - Log.e(TAG, "Caught an exception copying file:", e); + logerror("Caught an exception copying file:"); result = false; } audioContentValues.put(MediaStore.Audio.Media.IS_PENDING, 0); @@ -369,9 +415,9 @@ private boolean setupMediaLocationTest() { while (inputStream.read(bytes) != -1) { outputStream.write(bytes); } - Log.d(TAG, "Successfully wrote file to Movies directory"); + logdebug("Successfully wrote file to Movies directory"); } catch (IOException e) { - Log.e(TAG, "Caught an exception copying file:", e); + logerror("Caught an exception copying file:"); result = false; } videoContentValues.put(MediaStore.Video.Media.IS_PENDING, 0); @@ -412,17 +458,17 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, switch (requestCode) { case REQUEST_LOCATION_PERMISSION: if (!permissionGranted) { - Log.d(TAG, "The required permissions (" + String.join(", ", permissions) + logerror( "The required permissions (" + String.join(", ", permissions) + ") were not granted"); - runOnUiThread( - () -> mStatusTextView.setText(R.string.location_permission_required)); + //runOnUiThread( + // () -> mStatusAdapter.add(getResources().getString(R.string.location_permission_required)); } else { - Log.d(TAG, "The location permission was granted; rerunning setup tasks"); + logdebug( "The location permission was granted; rerunning setup tasks"); new SetupTestsAsyncTask().execute(); } break; default: - Log.d(TAG, "An unexpected request code of " + requestCode + " with permissions " + logerror("An unexpected request code of " + requestCode + " with permissions " + String.join(", ", permissions) + " + was received"); } @@ -434,21 +480,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case REQUEST_LOCATION_SETTINGS: LocationSettingsStates locationStates = LocationSettingsStates.fromIntent(data); - Log.d(TAG, + logdebug( "isLocationUsable: " + locationStates.isLocationUsable() + ", isGpsUsable: " + locationStates.isGpsUsable() + ", isNetworkLocationUsable: " + locationStates.isNetworkLocationUsable()); if (resultCode == Activity.RESULT_OK) { - Log.d(TAG, "Location settings have been updated; rerunning setup"); + logdebug("Location settings have been updated; rerunning setup"); new SetupTestsAsyncTask().execute(); } else { - Log.d(TAG, - "Location settings request completed with result code " + resultCode); - runOnUiThread(() -> mStatusTextView.setText(R.string.location_settings_update)); + logdebug("Location settings request completed with result code " + resultCode); } break; default: - Log.d(TAG, "An unknown activity result was received: requestCode = " + requestCode + logerror("An unknown activity result was received: requestCode = " + requestCode + ", resultCode = " + resultCode); } } diff --git a/niap-cc/Permissions/Companion/app/src/main/res/layout/activity_main.xml b/niap-cc/Permissions/Companion/app/src/main/res/layout/activity_main.xml index 42c3ca5..47e47fa 100644 --- a/niap-cc/Permissions/Companion/app/src/main/res/layout/activity_main.xml +++ b/niap-cc/Permissions/Companion/app/src/main/res/layout/activity_main.xml @@ -22,20 +22,23 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.android.certifications.niap.permissions.companion.MainActivity"> - -