Merge "Add summary for white balance feature" into qt-r1-dev
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ef68318..ff3f650 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -986,6 +986,18 @@
android:value="true" />
</activity>
+ <activity android:name=".Settings$ModuleLicensesActivity"
+ android:label="@string/module_license_title">
+ <intent-filter>
+ <action android:name="android.settings.MODULE_LICENSES" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.deviceinfo.legal.ModuleLicensesDashboard" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
<activity
android:name="Settings$ManageApplicationsActivity"
android:label="@string/applications_settings">
@@ -2271,6 +2283,7 @@
android:excludeFromRecents="true"
android:label=""
android:screenOrientation="nosensor"
+ android:taskAffinity="com.android.settings.FallbackHome"
android:theme="@style/FallbackHome">
<intent-filter android:priority="-1000">
<action android:name="android.intent.action.MAIN" />
@@ -2662,6 +2675,12 @@
android:resource="@xml/file_paths" />
</provider>
+ <provider
+ android:name=".deviceinfo.legal.ModuleLicenseProvider"
+ android:authorities="com.android.settings.module_licenses"
+ android:grantUriPermissions="true"
+ android:exported="false"/>
+
<activity android:name=".sim.SimPreferenceDialog"
android:theme="@style/Theme.AlertDialog"
android:excludeFromRecents="true" />
diff --git a/res/drawable/ic_arrow_down_24dp.xml b/res/drawable/ic_arrow_down_24dp.xml
index 8503511..f2efb4c 100644
--- a/res/drawable/ic_arrow_down_24dp.xml
+++ b/res/drawable/ic_arrow_down_24dp.xml
@@ -16,9 +16,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
+ android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="?android:attr/colorControlNormal"
+ android:fillColor="@android:color/white"
android:pathData="M12,16.41l-6.71,-6.7l1.42,-1.42l5.29,5.3l5.29,-5.3l1.42,1.42z"/>
</vector>
diff --git a/res/drawable/ic_content_copy_grey600_24dp.xml b/res/drawable/ic_content_copy_grey600_24dp.xml
index 827c66e..ba17ab6 100644
--- a/res/drawable/ic_content_copy_grey600_24dp.xml
+++ b/res/drawable/ic_content_copy_grey600_24dp.xml
@@ -1,9 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
+ android:tint="@*android:color/material_grey_600"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"
- android:fillColor="#757575"/>
+ android:fillColor="@android:color/white"/>
</vector>
diff --git a/res/drawable/ic_devices_other_opaque_black.xml b/res/drawable/ic_devices_other_opaque_black.xml
index 1b5af2d..40cf527 100644
--- a/res/drawable/ic_devices_other_opaque_black.xml
+++ b/res/drawable/ic_devices_other_opaque_black.xml
@@ -16,9 +16,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
+ android:tint="@android:color/black"
android:viewportWidth="24"
android:viewportHeight="24">
<path
- android:fillColor="#FF000000"
+ android:fillColor="@android:color/white"
android:pathData="M3,6h18L21,4L3,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h4v-2L3,18L3,6zM13,12L9,12v1.78c-0.61,0.55 -1,1.33 -1,2.22 0,0.89 0.39,1.67 1,2.22L9,20h4v-1.78c0.61,-0.55 1,-1.34 1,-2.22s-0.39,-1.67 -1,-2.22L13,12zM11,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM22,8h-6c-0.5,0 -1,0.5 -1,1v10c0,0.5 0.5,1 1,1h6c0.5,0 1,-0.5 1,-1L23,9c0,-0.5 -0.5,-1 -1,-1zM21,18h-4v-8h4v8z"/>
</vector>
diff --git a/res/drawable/ic_friction_lock_closed.xml b/res/drawable/ic_friction_lock_closed.xml
index 2f035e7..2c34060 100644
--- a/res/drawable/ic_friction_lock_closed.xml
+++ b/res/drawable/ic_friction_lock_closed.xml
@@ -17,9 +17,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
+ android:tint="?android:attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
- android:fillColor="?android:attr/colorControlNormal"
+ android:fillColor="@android:color/white"
android:pathData="M18,8h-1V6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2H6c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V10C20,8.9 19.1,8 18,8zM9,6c0,-1.66 1.34,-3 3,-3s3,1.34 3,3v2H9V6zM18,20H6V10h12V20zM12,17c1.1,0 2,-0.9 2,-2c0,-1.1 -0.9,-2 -2,-2c-1.1,0 -2,0.9 -2,2C10,16.1 10.9,17 12,17z"/>
</vector>
diff --git a/res/layout/contextual_slice_deferred_setup.xml b/res/layout/contextual_slice_deferred_setup.xml
index e695d1d..7d5b688 100644
--- a/res/layout/contextual_slice_deferred_setup.xml
+++ b/res/layout/contextual_slice_deferred_setup.xml
@@ -25,7 +25,7 @@
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:gravity="left"
+ android:gravity="start"
android:orientation="vertical"
android:paddingEnd="@dimen/contextual_card_padding_end"
android:paddingTop="@dimen/contextual_deferred_setup_card_padding_top"
diff --git a/res/xml/about_legal.xml b/res/xml/about_legal.xml
index c86276a..90b1985 100644
--- a/res/xml/about_legal.xml
+++ b/res/xml/about_legal.xml
@@ -42,6 +42,13 @@
android:title="@string/terms_title"
settings:controller="com.android.settings.deviceinfo.legal.TermsPreferenceController" />
+ <!-- Mainline Module License information -->
+ <Preference
+ android:key="module_license"
+ android:title="@string/module_license_title"
+ android:fragment="com.android.settings.deviceinfo.legal.ModuleLicensesDashboard"
+ settings:controller="com.android.settings.deviceinfo.legal.ModuleLicensesListPreferenceController" />
+
<!-- System WebView License information -->
<Preference
android:key="webview_license"
diff --git a/res/xml/module_licenses.xml b/res/xml/module_licenses.xml
new file mode 100644
index 0000000..005b483
--- /dev/null
+++ b/res/xml/module_licenses.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ Copyright (C) 2019 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
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="module_licenses"
+ android:title="@string/module_license_title">
+ <PreferenceCategory
+ android:key="module_licenses_category"
+ android:layout="@layout/preference_category_no_label"
+ android:title="@string/summary_placeholder"
+ settings:controller="com.android.settings.deviceinfo.legal.ModuleLicensesPreferenceController" />
+</PreferenceScreen>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index b4ebc57..ab59da4 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -56,6 +56,7 @@
public static class NightDisplaySettingsActivity extends SettingsActivity { /* empty */ }
public static class NightDisplaySuggestionActivity extends NightDisplaySettingsActivity { /* empty */ }
public static class MyDeviceInfoActivity extends SettingsActivity { /* empty */ }
+ public static class ModuleLicensesActivity extends SettingsActivity { /* empty */ }
public static class ApplicationSettingsActivity extends SettingsActivity { /* empty */ }
public static class ManageApplicationsActivity extends SettingsActivity { /* empty */ }
public static class ManageAssistActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 75db3e1..c4b1400 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -131,11 +131,6 @@
"device_identifier_access_restrictions_disabled";
/**
- * Whether to show the Permissions Hub.
- */
- public static final String PROPERTY_PERMISSIONS_HUB_ENABLED = "permissions_hub_enabled";
-
- /**
* Finds a matching activity for a preference's intent. If a matching
* activity is not found, it will remove the preference.
*
diff --git a/src/com/android/settings/accounts/RemoveAccountPreferenceController.java b/src/com/android/settings/accounts/RemoveAccountPreferenceController.java
index 1bc30d0..5c6e6bb 100644
--- a/src/com/android/settings/accounts/RemoveAccountPreferenceController.java
+++ b/src/com/android/settings/accounts/RemoveAccountPreferenceController.java
@@ -191,7 +191,11 @@
}
final RemoveAccountFailureDialog dialog = new RemoveAccountFailureDialog();
dialog.setTargetFragment(parent, 0);
- dialog.show(parent.getFragmentManager(), FAILED_REMOVAL_DIALOG);
+ try {
+ dialog.show(parent.getFragmentManager(), FAILED_REMOVAL_DIALOG);
+ } catch (IllegalStateException e) {
+ Log.w(TAG, "Can't show RemoveAccountFailureDialog. " + e.getMessage());
+ }
}
@Override
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index b35a974..5a81e71 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -72,6 +72,7 @@
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
+import com.android.settings.deviceinfo.legal.ModuleLicensesDashboard;
import com.android.settings.display.NightDisplaySettings;
import com.android.settings.dream.DreamSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
@@ -175,6 +176,7 @@
UserDictionarySettings.class.getName(),
DisplaySettings.class.getName(),
MyDeviceInfoFragment.class.getName(),
+ ModuleLicensesDashboard.class.getName(),
ManageApplications.class.getName(),
FirmwareVersionSettings.class.getName(),
ManageAssist.class.getName(),
@@ -318,6 +320,7 @@
Settings.DateTimeSettingsActivity.class.getName(),
Settings.EnterprisePrivacySettingsActivity.class.getName(),
Settings.MyDeviceInfoActivity.class.getName(),
+ Settings.ModuleLicensesActivity.class.getName(),
UserBackupSettingsActivity.class.getName(),
};
}
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicensePreference.java b/src/com/android/settings/deviceinfo/legal/ModuleLicensePreference.java
new file mode 100644
index 0000000..e012275
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicensePreference.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ModuleInfo;
+import android.util.Log;
+import android.widget.Toast;
+
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+
+/**
+ * Preference in a list that represents a mainline module that has a licenses file.
+ */
+public class ModuleLicensePreference extends Preference {
+ private static final String TAG = "ModuleLicensePreference";
+ private final ModuleInfo mModule;
+
+ public ModuleLicensePreference(Context context, ModuleInfo module) {
+ super(context);
+ mModule = module;
+ setKey(module.getPackageName());
+ setTitle(module.getName());
+ }
+
+ @Override
+ protected void onClick() {
+ // Kick off external viewer due to WebView security restrictions (Settings cannot use
+ // WebView because it is UID 1000).
+ Intent intent = new Intent(Intent.ACTION_VIEW)
+ .setDataAndType(
+ ModuleLicenseProvider.getUriForPackage(mModule.getPackageName()),
+ ModuleLicenseProvider.LICENSE_FILE_MIME_TYPE)
+ .putExtra(Intent.EXTRA_TITLE, mModule.getName())
+ .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
+ .addCategory(Intent.CATEGORY_DEFAULT)
+ .setPackage("com.android.htmlviewer");
+ try {
+ getContext().startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Log.e(TAG, "Failed to find viewer", e);
+ showError();
+ }
+ }
+
+ private void showError() {
+ Toast.makeText(
+ getContext(), R.string.settings_license_activity_unavailable, Toast.LENGTH_LONG)
+ .show();
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicenseProvider.java b/src/com/android/settings/deviceinfo/legal/ModuleLicenseProvider.java
new file mode 100644
index 0000000..6731c69
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicenseProvider.java
@@ -0,0 +1,194 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import android.content.ContentProvider;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.ParcelFileDescriptor;
+import android.util.Log;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.core.util.Preconditions;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
+public class ModuleLicenseProvider extends ContentProvider {
+ private static final String TAG = "ModuleLicenseProvider";
+
+ public static final String AUTHORITY = "com.android.settings.module_licenses";
+ static final String GZIPPED_LICENSE_FILE_NAME = "NOTICE.html.gz";
+ static final String LICENSE_FILE_NAME = "NOTICE.html";
+ static final String LICENSE_FILE_MIME_TYPE = "text/html";
+ static final String PREFS_NAME = "ModuleLicenseProvider";
+
+ @Override
+ public boolean onCreate() {
+ return true;
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
+ String sortOrder) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ checkUri(getContext(), uri);
+ return LICENSE_FILE_MIME_TYPE;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ParcelFileDescriptor openFile(Uri uri, String mode) {
+ final Context context = getContext();
+ checkUri(context, uri);
+ Preconditions.checkArgument("r".equals(mode), "Read is the only supported mode");
+
+ try {
+ String packageName = uri.getPathSegments().get(0);
+ File cachedFile = getCachedHtmlFile(context, packageName);
+ if (isCachedHtmlFileOutdated(context, packageName)) {
+ try (InputStream in = new GZIPInputStream(
+ getPackageAssetManager(context.getPackageManager(), packageName)
+ .open(GZIPPED_LICENSE_FILE_NAME))) {
+ File directory = getCachedFileDirectory(context, packageName);
+ if (!directory.exists()) {
+ directory.mkdir();
+ }
+ Files.copy(in, cachedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+ }
+ // Now that the file is saved, write the package's version code to shared prefs
+ SharedPreferences.Editor editor = getPrefs(context).edit();
+ editor.putLong(
+ packageName,
+ getPackageInfo(context, packageName).getLongVersionCode())
+ .commit();
+ }
+ return ParcelFileDescriptor.open(cachedFile, ParcelFileDescriptor.MODE_READ_ONLY);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.wtf(TAG, "checkUri should have already caught this error", e);
+ } catch (IOException e) {
+ Log.e(TAG, "Could not open file descriptor", e);
+ }
+ return null;
+ }
+
+ /**
+ * Returns true if the cached file for the given package is outdated. A cached file is
+ * outdated if one of the following are true:
+ * 1. the shared prefs does not contain a version code for this package
+ * 2. The version code does not match the package's version code
+ * 3. There is no file or the file is empty.
+ */
+ @VisibleForTesting
+ static boolean isCachedHtmlFileOutdated(Context context, String packageName)
+ throws PackageManager.NameNotFoundException {
+ SharedPreferences prefs = getPrefs(context);
+ File file = getCachedHtmlFile(context, packageName);
+ return !prefs.contains(packageName)
+ || prefs.getLong(packageName, 0L)
+ != getPackageInfo(context, packageName).getLongVersionCode()
+ || !file.exists() || file.length() == 0;
+ }
+
+ static AssetManager getPackageAssetManager(PackageManager packageManager, String packageName)
+ throws PackageManager.NameNotFoundException {
+ return packageManager.getResourcesForApplication(
+ packageManager.getPackageInfo(packageName, PackageManager.MATCH_APEX)
+ .applicationInfo)
+ .getAssets();
+ }
+
+ static Uri getUriForPackage(String packageName) {
+ return new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(AUTHORITY)
+ .appendPath(packageName)
+ .appendPath(LICENSE_FILE_NAME)
+ .build();
+ }
+
+ private static void checkUri(Context context, Uri uri) {
+ List<String> pathSegments = uri.getPathSegments();
+ // A URI is valid iff it:
+ // 1. is a content URI
+ // 2. uses the correct authority
+ // 3. has exactly 2 segments and the last one is NOTICE.html
+ // 4. (checked below) first path segment is the package name of a module
+ if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())
+ || !AUTHORITY.equals(uri.getAuthority())
+ || pathSegments == null
+ || pathSegments.size() != 2
+ || !LICENSE_FILE_NAME.equals(pathSegments.get(1))) {
+ throw new IllegalArgumentException(uri + "is not a valid URI");
+ }
+ // Grab the first path segment, which is the package name of the module and make sure that
+ // there's actually a module for that package. getModuleInfo will throw if it does not
+ // exist.
+ try {
+ context.getPackageManager().getModuleInfo(pathSegments.get(0), 0 /* flags */);
+ } catch (PackageManager.NameNotFoundException e) {
+ throw new IllegalArgumentException(uri + "is not a valid URI", e);
+ }
+ }
+
+ private static File getCachedFileDirectory(Context context, String packageName) {
+ return new File(context.getCacheDir(), packageName);
+ }
+
+ private static File getCachedHtmlFile(Context context, String packageName) {
+ return new File(context.getCacheDir() + "/" + packageName, LICENSE_FILE_NAME);
+ }
+
+ private static PackageInfo getPackageInfo(Context context, String packageName)
+ throws PackageManager.NameNotFoundException {
+ return context.getPackageManager().getPackageInfo(packageName, PackageManager.MATCH_APEX);
+ }
+
+ private static SharedPreferences getPrefs(Context context) {
+ return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicensesDashboard.java b/src/com/android/settings/deviceinfo/legal/ModuleLicensesDashboard.java
new file mode 100644
index 0000000..f74b68f
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicensesDashboard.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import android.app.settings.SettingsEnums;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+
+public class ModuleLicensesDashboard extends DashboardFragment {
+ private static final String TAG = "ModuleLicensesDashboard";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.MODULE_LICENSES_DASHBOARD;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.module_licenses;
+ }
+
+ @Override
+ public int getHelpResource() {
+ return 0;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java b/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java
new file mode 100644
index 0000000..9faff85
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceController.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import android.content.Context;
+import android.content.pm.ModuleInfo;
+import android.content.pm.PackageManager;
+
+import com.android.settings.core.BasePreferenceController;
+
+import java.util.List;
+
+public class ModuleLicensesListPreferenceController extends BasePreferenceController {
+ public ModuleLicensesListPreferenceController(Context context,
+ String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ PackageManager packageManager = mContext.getPackageManager();
+ List<ModuleInfo> modules = packageManager.getInstalledModules(0 /* flags */);
+ return modules.stream().anyMatch(new ModuleLicensesPreferenceController.Predicate(mContext))
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/legal/ModuleLicensesPreferenceController.java b/src/com/android/settings/deviceinfo/legal/ModuleLicensesPreferenceController.java
new file mode 100644
index 0000000..dd5edbb
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/legal/ModuleLicensesPreferenceController.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import android.content.Context;
+import android.content.pm.ModuleInfo;
+import android.content.pm.PackageManager;
+
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceScreen;
+
+import com.android.internal.util.ArrayUtils;
+import com.android.settings.core.BasePreferenceController;
+
+import java.io.IOException;
+import java.util.Comparator;
+import java.util.List;
+
+public class ModuleLicensesPreferenceController extends BasePreferenceController {
+ public ModuleLicensesPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE_UNSEARCHABLE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ PackageManager packageManager = mContext.getPackageManager();
+ List<ModuleInfo> modules = packageManager.getInstalledModules(0 /* flags */);
+ PreferenceGroup group = screen.findPreference(getPreferenceKey());
+ modules.stream()
+ .sorted(Comparator.comparing(o -> o.getName().toString()))
+ .filter(new Predicate(mContext))
+ .forEach(module ->
+ group.addPreference(
+ new ModuleLicensePreference(group.getContext(), module)));
+ }
+
+ static class Predicate implements java.util.function.Predicate<ModuleInfo> {
+ private final Context mContext;
+
+ public Predicate(Context context) {
+ mContext = context;
+ }
+ @Override
+ public boolean test(ModuleInfo module) {
+ try {
+ return ArrayUtils.contains(
+ ModuleLicenseProvider.getPackageAssetManager(
+ mContext.getPackageManager(),
+ module.getPackageName())
+ .list(""),
+ ModuleLicenseProvider.GZIPPED_LICENSE_FILE_NAME);
+ } catch (IOException | PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+ }
+}
diff --git a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
index c835a51..2f0dafd 100644
--- a/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
+++ b/src/com/android/settings/location/RecentLocationAccessPreferenceController.java
@@ -64,9 +64,7 @@
@Override
public boolean isAvailable() {
- return Boolean.parseBoolean(
- DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED));
+ return false;
}
@Override
diff --git a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
index 399216c..28533df 100644
--- a/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
+++ b/src/com/android/settings/privacy/PermissionBarChartPreferenceController.java
@@ -89,10 +89,7 @@
@Override
public int getAvailabilityStatus() {
- return Boolean.parseBoolean(
- DeviceConfig.getProperty(DeviceConfig.NAMESPACE_PRIVACY,
- com.android.settings.Utils.PROPERTY_PERMISSIONS_HUB_ENABLED)) ?
- AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
+ return UNSUPPORTED_ON_DEVICE;
}
@Override
diff --git a/tests/robotests/assets/grandfather_not_implementing_index_provider b/tests/robotests/assets/grandfather_not_implementing_index_provider
index b950f30..061a81e 100644
--- a/tests/robotests/assets/grandfather_not_implementing_index_provider
+++ b/tests/robotests/assets/grandfather_not_implementing_index_provider
@@ -33,6 +33,7 @@
com.android.settings.deviceinfo.PrivateVolumeSettings
com.android.settings.deviceinfo.PublicVolumeSettings
com.android.settings.deviceinfo.StorageProfileFragment
+com.android.settings.deviceinfo.legal.ModuleLicensesDashboard
com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionCamera
com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionLocation
com.android.settings.enterprise.ApplicationListFragment$AdminGrantedPermissionMicrophone
diff --git a/tests/robotests/res/values/overlayable_icons_test.xml b/tests/robotests/res/values/overlayable_icons_test.xml
index bf87f3b..b3a43aa 100644
--- a/tests/robotests/res/values/overlayable_icons_test.xml
+++ b/tests/robotests/res/values/overlayable_icons_test.xml
@@ -26,8 +26,6 @@
<item>@drawable/ic_arrow_back</item>
<item>@drawable/ic_arrow_down_24dp</item>
<item>@drawable/ic_battery_charging_full</item>
- <item>@drawable/ic_battery_saver_accent_24dp</item>
- <item>@drawable/ic_battery_status_bad_24dp</item>
<item>@drawable/ic_battery_status_good_24dp</item>
<item>@drawable/ic_battery_status_maybe_24dp</item>
<item>@drawable/ic_call_24dp</item>
@@ -38,13 +36,13 @@
<item>@drawable/ic_content_copy_grey600_24dp</item>
<item>@drawable/ic_data_saver</item>
<item>@drawable/ic_delete</item>
- <item>@drawable/ic_delete_accent</item>
<item>@drawable/ic_devices_other</item>
<item>@drawable/ic_devices_other_opaque_black</item>
<item>@drawable/ic_do_not_disturb_on_24dp</item>
<item>@drawable/ic_eject_24dp</item>
<item>@drawable/ic_expand_less</item>
<item>@drawable/ic_expand_more_inverse</item>
+ <item>@drawable/ic_find_in_page_24px</item>
<item>@drawable/ic_folder_vd_theme_24</item>
<item>@drawable/ic_friction_lock_closed</item>
<item>@drawable/ic_gray_scale_24dp</item>
@@ -73,7 +71,9 @@
<item>@drawable/ic_settings_delete</item>
<item>@drawable/ic_settings_display_white</item>
<item>@drawable/ic_settings_home</item>
+ <item>@drawable/ic_settings_language</item>
<item>@drawable/ic_settings_location</item>
+ <item>@drawable/ic_settings_multiuser</item>
<item>@drawable/ic_settings_night_display</item>
<item>@drawable/ic_settings_open</item>
<item>@drawable/ic_settings_print</item>
@@ -82,7 +82,6 @@
<item>@drawable/ic_settings_sim</item>
<item>@drawable/ic_settings_system_dashboard_white</item>
<item>@drawable/ic_settings_wireless</item>
- <item>@drawable/ic_settings_wireless_white</item>
<item>@drawable/ic_storage</item>
<item>@drawable/ic_storage_white</item>
<item>@drawable/ic_suggestion_night_display</item>
@@ -92,5 +91,6 @@
<item>@drawable/ic_volume_ringer_vibrate</item>
<item>@drawable/ic_volume_up_24dp</item>
<item>@drawable/ic_vpn_key</item>
+ <item>@drawable/ic_wifi_tethering</item>
</array>
</resources>
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensePreferenceTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensePreferenceTest.java
new file mode 100644
index 0000000..cdf082f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensePreferenceTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ModuleInfo;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(RobolectricTestRunner.class)
+public class ModuleLicensePreferenceTest {
+ public static final String PACKAGE_NAME = "com.android.test_package";
+ public static final String NAME = "Test Package";
+ private Context mContext;
+ private ModuleInfo mModuleInfo;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = Robolectric.setupActivity(Activity.class);
+ mModuleInfo = new ModuleInfo();
+ mModuleInfo.setPackageName(PACKAGE_NAME);
+ mModuleInfo.setName(NAME);
+ }
+
+ @Test
+ public void ctor_properKeyAndTitle() {
+ ModuleLicensePreference pref = new ModuleLicensePreference(mContext, mModuleInfo);
+
+ assertThat(pref.getKey()).isEqualTo(PACKAGE_NAME);
+ assertThat(pref.getTitle()).isEqualTo(NAME);
+ }
+
+ @Test
+ public void onClick_sendsCorrectIntent() {
+ ModuleLicensePreference pref = new ModuleLicensePreference(mContext, mModuleInfo);
+
+ pref.onClick();
+
+ Intent intent = ShadowApplication.getInstance().getNextStartedActivity();
+ assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
+ assertThat(intent.getData())
+ .isEqualTo(ModuleLicenseProvider.getUriForPackage(PACKAGE_NAME));
+ assertThat(intent.getType()).isEqualTo(ModuleLicenseProvider.LICENSE_FILE_MIME_TYPE);
+ assertThat(intent.getCharSequenceExtra(Intent.EXTRA_TITLE)).isEqualTo(NAME);
+ assertThat(intent.getFlags()).isEqualTo(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ assertThat(intent.getCategories()).contains(Intent.CATEGORY_DEFAULT);
+ assertThat(intent.getPackage()).isEqualTo("com.android.htmlviewer");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicenseProviderTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicenseProviderTest.java
new file mode 100644
index 0000000..b65137b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicenseProviderTest.java
@@ -0,0 +1,393 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import static com.android.settings.deviceinfo.legal.ModuleLicenseProvider.LICENSE_FILE_NAME;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ModuleInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.AssetManager;
+import android.content.res.Resources;
+import android.net.Uri;
+import android.os.ParcelFileDescriptor;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+@RunWith(RobolectricTestRunner.class)
+public class ModuleLicenseProviderTest {
+ public static final String PACKAGE_NAME = "com.android.test_package";
+ @Test
+ public void onCreate_returnsTrue() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ assertThat(provider.onCreate()).isTrue();
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void query_throwsUnsupportedOperationException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.query(null, null, null, null, null);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void insert_throwsUnsupportedOperationException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.insert(null, null);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void delete_throwsUnsupportedOperationException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.delete(null, null, null);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void update_throwsUnsupportedOperationException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.update(null, null, null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_notContentScheme_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.getType(new Uri.Builder()
+ .scheme("badscheme")
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_invalidAuthority_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority("notmyauthority")
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_emptyPath_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .build());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_missingPackageName_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(LICENSE_FILE_NAME)
+ .build());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_missingFileName_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .build());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_incorrectFileName_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath("badname.txt")
+ .build());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void getType_packageNotAModule_throwsIllegalArgumentException()
+ throws PackageManager.NameNotFoundException {
+ ModuleLicenseProvider provider = spy(new ModuleLicenseProvider());
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(provider.getContext()).thenReturn(context);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ when(packageManager.getModuleInfo(PACKAGE_NAME, 0))
+ .thenThrow(new PackageManager.NameNotFoundException());
+
+ provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build());
+ }
+
+ @Test
+ public void getType_validUri_returnsHtmlMimeType()
+ throws PackageManager.NameNotFoundException {
+ ModuleLicenseProvider provider = spy(new ModuleLicenseProvider());
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(provider.getContext()).thenReturn(context);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ when(packageManager.getModuleInfo(PACKAGE_NAME, 0))
+ .thenReturn(new ModuleInfo());
+
+ assertThat(provider.getType(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build())).isEqualTo(ModuleLicenseProvider.LICENSE_FILE_MIME_TYPE);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_notContentScheme_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.openFile(new Uri.Builder()
+ .scheme("badscheme")
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_invalidAuthority_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority("notmyauthority")
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_emptyPath_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_missingPackageName_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(LICENSE_FILE_NAME)
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_missingFileName_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_incorrectFileName_throwsIllegalArgumentException() {
+ ModuleLicenseProvider provider = new ModuleLicenseProvider();
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath("badname.txt")
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_packageNotAModule_throwsIllegalArgumentException()
+ throws PackageManager.NameNotFoundException {
+ ModuleLicenseProvider provider = spy(new ModuleLicenseProvider());
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(provider.getContext()).thenReturn(context);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ when(packageManager.getModuleInfo(PACKAGE_NAME, 0))
+ .thenThrow(new PackageManager.NameNotFoundException());
+
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build(), "r");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void openFile_validUri_notReadMode_throwsIllegalArgumentException()
+ throws PackageManager.NameNotFoundException {
+ ModuleLicenseProvider provider = spy(new ModuleLicenseProvider());
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(provider.getContext()).thenReturn(context);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ when(packageManager.getModuleInfo(PACKAGE_NAME, 0))
+ .thenReturn(new ModuleInfo());
+
+ provider.openFile(new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(ModuleLicenseProvider.AUTHORITY)
+ .appendPath(PACKAGE_NAME)
+ .appendPath(LICENSE_FILE_NAME)
+ .build(), "badmode");
+ }
+
+ @Test
+ public void isCachedHtmlFileOutdated_packageNotInSharedPrefs_returnTrue()
+ throws PackageManager.NameNotFoundException {
+ Context context = RuntimeEnvironment.application;
+ context.getSharedPreferences(ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit().clear().commit();
+
+ assertThat(ModuleLicenseProvider.isCachedHtmlFileOutdated(context, PACKAGE_NAME)).isTrue();
+ }
+
+ @Test
+ public void isCachedHtmlFileOutdated_versionCodeDiffersFromSharedPref_returnTrue()
+ throws PackageManager.NameNotFoundException {
+ Context context = spy(RuntimeEnvironment.application);
+ SharedPreferences.Editor editor = context.getSharedPreferences(
+ ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit();
+ editor.clear().commit();
+ editor.putLong(PACKAGE_NAME, 900L).commit();
+ PackageManager packageManager = mock(PackageManager.class);
+ doReturn(packageManager).when(context).getPackageManager();
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.setLongVersionCode(1000L);
+ when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+
+ assertThat(ModuleLicenseProvider.isCachedHtmlFileOutdated(context, PACKAGE_NAME)).isTrue();
+ }
+
+ @Test
+ public void isCachedHtmlFileOutdated_fileDoesNotExist_returnTrue()
+ throws PackageManager.NameNotFoundException {
+ Context context = spy(RuntimeEnvironment.application);
+ context.getSharedPreferences(ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit().clear().commit();
+ SharedPreferences.Editor editor = context.getSharedPreferences(
+ ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit();
+ editor.clear().commit();
+ editor.putLong(PACKAGE_NAME, 1000L).commit();
+ PackageManager packageManager = mock(PackageManager.class);
+ doReturn(packageManager).when(context).getPackageManager();
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.setLongVersionCode(1000L);
+ when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+ new File(context.getCacheDir() + "/" + PACKAGE_NAME, LICENSE_FILE_NAME).delete();
+
+ assertThat(ModuleLicenseProvider.isCachedHtmlFileOutdated(context, PACKAGE_NAME)).isTrue();
+ }
+
+ @Test
+ public void isCachedHtmlFileOutdated_fileIsEmpty_returnTrue()
+ throws PackageManager.NameNotFoundException, IOException {
+ Context context = spy(RuntimeEnvironment.application);
+ context.getSharedPreferences(ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit().clear().commit();
+ SharedPreferences.Editor editor = context.getSharedPreferences(
+ ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit();
+ editor.clear().commit();
+ editor.putLong(PACKAGE_NAME, 1000L).commit();
+ PackageManager packageManager = mock(PackageManager.class);
+ doReturn(packageManager).when(context).getPackageManager();
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.setLongVersionCode(1000L);
+ when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+ new File(context.getCacheDir(), PACKAGE_NAME).mkdir();
+ File file = new File(context.getCacheDir() + "/" + PACKAGE_NAME, LICENSE_FILE_NAME);
+ file.delete();
+ file.createNewFile();
+
+ assertThat(ModuleLicenseProvider.isCachedHtmlFileOutdated(context, PACKAGE_NAME)).isTrue();
+ }
+
+ @Test
+ public void isCachedHtmlFileOutdated_notOutdated_returnFalse()
+ throws PackageManager.NameNotFoundException, IOException {
+ Context context = spy(RuntimeEnvironment.application);
+ context.getSharedPreferences(ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit().clear().commit();
+ SharedPreferences.Editor editor = context.getSharedPreferences(
+ ModuleLicenseProvider.PREFS_NAME, Context.MODE_PRIVATE)
+ .edit();
+ editor.clear().commit();
+ editor.putLong(PACKAGE_NAME, 1000L).commit();
+ PackageManager packageManager = mock(PackageManager.class);
+ doReturn(packageManager).when(context).getPackageManager();
+ PackageInfo packageInfo = new PackageInfo();
+ packageInfo.setLongVersionCode(1000L);
+ when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+ new File(context.getCacheDir(), PACKAGE_NAME).mkdir();
+ File file = new File(context.getCacheDir() + "/" + PACKAGE_NAME, LICENSE_FILE_NAME);
+ file.delete();
+ file.createNewFile();
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
+ writer.write("test");
+ }
+
+ assertThat(ModuleLicenseProvider.isCachedHtmlFileOutdated(context, PACKAGE_NAME)).isFalse();
+ }
+
+ @Test
+ public void getUriForPackage_returnsProperlyFormattedUri() {
+ assertThat(ModuleLicenseProvider.getUriForPackage(PACKAGE_NAME))
+ .isEqualTo(Uri.parse("content://com.android.settings.module_licenses/com.android.test_package/NOTICE.html"));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceControllerTest.java
new file mode 100644
index 0000000..0ca22fb
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensesListPreferenceControllerTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import static com.android.settings.deviceinfo.legal.ModuleLicenseProvider.GZIPPED_LICENSE_FILE_NAME;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ModuleInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
+import android.content.res.Resources;
+
+import com.android.settings.core.BasePreferenceController;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+
+import java.io.IOException;
+import java.util.Collections;
+
+@RunWith(RobolectricTestRunner.class)
+public class ModuleLicensesListPreferenceControllerTest {
+ private static final String PREFERENCE_KEY = "key";
+ private static final String PACKAGE_NAME = "com.android.test_package";
+
+ @Test
+ public void getAvailabilityStatus_validLicenses_returnsAvailable()
+ throws PackageManager.NameNotFoundException, IOException {
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ ModuleInfo moduleInfo = new ModuleInfo();
+ moduleInfo.setPackageName(PACKAGE_NAME);
+ when(packageManager.getInstalledModules(0))
+ .thenReturn(Collections.singletonList(moduleInfo));
+ PackageInfo packageInfo = new PackageInfo();
+ ApplicationInfo applicationInfo = new ApplicationInfo();
+ packageInfo.applicationInfo = applicationInfo;
+ when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(
+ packageInfo);
+ Resources resources = mock(Resources.class);
+ when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
+ AssetManager manager = mock(AssetManager.class);
+ when(resources.getAssets()).thenReturn(manager);
+ when(manager.list("")).thenReturn(new String[]{GZIPPED_LICENSE_FILE_NAME});
+
+ ModuleLicensesListPreferenceController controller =
+ new ModuleLicensesListPreferenceController(context, PREFERENCE_KEY);
+ assertThat(controller.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noModules_returnsConditionallyUnavailable() {
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ when(packageManager.getInstalledModules(0))
+ .thenReturn(Collections.emptyList());
+
+ ModuleLicensesListPreferenceController controller =
+ new ModuleLicensesListPreferenceController(context, PREFERENCE_KEY);
+ assertThat(controller.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noLicenses_returnsConditionallyUnavailable()
+ throws PackageManager.NameNotFoundException, IOException {
+ Context context = mock(Context.class);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ ModuleInfo moduleInfo = new ModuleInfo();
+ moduleInfo.setPackageName(PACKAGE_NAME);
+ when(packageManager.getInstalledModules(0))
+ .thenReturn(Collections.singletonList(moduleInfo));
+ PackageInfo packageInfo = new PackageInfo();
+ ApplicationInfo applicationInfo = new ApplicationInfo();
+ packageInfo.applicationInfo = applicationInfo;
+ when(packageManager.getPackageInfo(PACKAGE_NAME, PackageManager.MATCH_APEX)).thenReturn(
+ packageInfo);
+ Resources resources = mock(Resources.class);
+ when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
+ AssetManager manager = mock(AssetManager.class);
+ when(resources.getAssets()).thenReturn(manager);
+ when(manager.list("")).thenReturn(new String[]{});
+
+ ModuleLicensesListPreferenceController controller =
+ new ModuleLicensesListPreferenceController(context, PREFERENCE_KEY);
+ assertThat(controller.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensesPreferenceControllerTest.java
new file mode 100644
index 0000000..bf1b01e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/legal/ModuleLicensesPreferenceControllerTest.java
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2019 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.settings.deviceinfo.legal;
+
+import static com.android.settings.deviceinfo.legal.ModuleLicenseProvider.GZIPPED_LICENSE_FILE_NAME;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.ModuleInfo;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.content.res.AssetManager;
+import android.content.res.Resources;
+import android.util.AttributeSet;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceGroup;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class ModuleLicensesPreferenceControllerTest {
+
+ private static final String PREFERENCE_KEY = "key";
+ private static final String MODULE_1_NAME = "Module 1";
+ private static final String MODULE_1_PACKAGE_NAME = "com.android.module_one";
+ private static final String MODULE_2_NAME = "Module 2";
+ private static final String MODULE_2_PACKAGE_NAME = "com.android.module_two";
+ private ModuleInfo mModuleOne;
+ private ModuleInfo mModuleTwo;
+
+ @Before
+ public void setUp() {
+ mModuleOne = new ModuleInfo();
+ mModuleOne.setName(MODULE_1_NAME);
+ mModuleOne.setPackageName(MODULE_1_PACKAGE_NAME);
+ mModuleTwo = new ModuleInfo();
+ mModuleTwo.setName(MODULE_2_NAME);
+ mModuleTwo.setPackageName(MODULE_2_PACKAGE_NAME);
+ }
+
+ @Test
+ public void displayPreference_alphabeticalOrder()
+ throws PackageManager.NameNotFoundException, IOException {
+ Context context = mock(Context.class);
+ ModuleLicensesPreferenceController controller =
+ new ModuleLicensesPreferenceController(context, PREFERENCE_KEY);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ PreferenceScreen screen = mock(PreferenceScreen.class);
+ PreferenceGroup group = spy(new MockPreferenceGroup(RuntimeEnvironment.application, null));
+ when(screen.findPreference(PREFERENCE_KEY)).thenReturn(group);
+ when(group.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+ when(packageManager.getInstalledModules(0))
+ .thenReturn(Arrays.asList(mModuleTwo, mModuleOne));
+ PackageInfo packageInfo = new PackageInfo();
+ ApplicationInfo applicationInfo = new ApplicationInfo();
+ packageInfo.applicationInfo = applicationInfo;
+ when(packageManager.getPackageInfo(MODULE_1_PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+ when(packageManager.getPackageInfo(MODULE_2_PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+ Resources resources = mock(Resources.class);
+ when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
+ AssetManager manager = mock(AssetManager.class);
+ when(resources.getAssets()).thenReturn(manager);
+ when(manager.list("")).thenReturn(new String[]{GZIPPED_LICENSE_FILE_NAME});
+
+ controller.displayPreference(screen);
+
+ assertThat(group.getPreferenceCount()).isEqualTo(2);
+ assertThat(group.getPreference(0).getTitle()).isEqualTo(MODULE_1_NAME);
+ assertThat(group.getPreference(1).getTitle()).isEqualTo(MODULE_2_NAME);
+ }
+
+ @Test
+ public void displayPreference_includeOnlyModulesWithLicenseFile()
+ throws PackageManager.NameNotFoundException, IOException {
+ Context context = mock(Context.class);
+ ModuleLicensesPreferenceController controller =
+ new ModuleLicensesPreferenceController(context, PREFERENCE_KEY);
+ PackageManager packageManager = mock(PackageManager.class);
+ when(context.getPackageManager()).thenReturn(packageManager);
+ PreferenceScreen screen = mock(PreferenceScreen.class);
+ PreferenceGroup group = spy(new MockPreferenceGroup(RuntimeEnvironment.application, null));
+ when(screen.findPreference(PREFERENCE_KEY)).thenReturn(group);
+ when(group.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
+ when(packageManager.getInstalledModules(0))
+ .thenReturn(Arrays.asList(mModuleTwo, mModuleOne));
+ PackageInfo packageInfo = new PackageInfo();
+ ApplicationInfo applicationInfo = new ApplicationInfo();
+ packageInfo.applicationInfo = applicationInfo;
+ when(packageManager.getPackageInfo(MODULE_1_PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo);
+ Resources resources = mock(Resources.class);
+ when(packageManager.getResourcesForApplication(applicationInfo)).thenReturn(resources);
+ AssetManager manager = mock(AssetManager.class);
+ when(resources.getAssets()).thenReturn(manager);
+ when(manager.list("")).thenReturn(new String[]{GZIPPED_LICENSE_FILE_NAME});
+ PackageInfo packageInfo2 = new PackageInfo();
+ ApplicationInfo applicationInfo2 = new ApplicationInfo();
+ packageInfo2.applicationInfo = applicationInfo2;
+ when(packageManager.getPackageInfo(MODULE_2_PACKAGE_NAME, PackageManager.MATCH_APEX))
+ .thenReturn(packageInfo2);
+ Resources resources2 = mock(Resources.class);
+ when(packageManager.getResourcesForApplication(applicationInfo2)).thenReturn(resources2);
+ AssetManager manager2 = mock(AssetManager.class);
+ when(resources2.getAssets()).thenReturn(manager2);
+ when(manager2.list("")).thenReturn(new String[]{});
+
+ controller.displayPreference(screen);
+
+ assertThat(group.getPreferenceCount()).isEqualTo(1);
+ assertThat(group.getPreference(0).getTitle()).isEqualTo(MODULE_1_NAME);
+ }
+
+ private static class MockPreferenceGroup extends PreferenceGroup {
+ List<Preference> mList = new ArrayList<>();
+
+ public MockPreferenceGroup(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean addPreference(Preference preference) {
+ mList.add(preference);
+ return true;
+ }
+
+ @Override
+ public int getPreferenceCount() {
+ return mList.size();
+ }
+
+ @Override
+ public Preference getPreference(int index) {
+ return mList.get(index);
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
index 71a80de..aeda699 100644
--- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java
@@ -92,75 +92,4 @@
// We have not yet set the property to show the Permissions Hub.
assertThat(mController.isAvailable()).isEqualTo(false);
}
-
- @Test
- public void isAvailable_permissionHubEnabled_shouldReturnTrue() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
-
- assertThat(mController.isAvailable()).isEqualTo(true);
- }
-
- /** Verifies the title text, details text are correct, and the click listener is set. */
- @Test
- @Ignore
- public void updateState_whenAppListIsEmpty_shouldDisplayTitleTextAndDetailsText() {
- doReturn(new ArrayList<>()).when(mRecentLocationApps).getAppListSorted();
- mController.displayPreference(mScreen);
- mController.updateState(mLayoutPreference);
-
- final TextView title = mAppEntitiesHeaderView.findViewById(R.id.header_title);
- assertThat(title.getText()).isEqualTo(
- mContext.getText(R.string.location_category_recent_location_access));
- final TextView details = mAppEntitiesHeaderView.findViewById(R.id.header_details);
- assertThat(details.getText()).isEqualTo(
- mContext.getText(R.string.location_recent_location_access_view_details));
- assertThat(details.hasOnClickListeners()).isTrue();
- }
-
- @Test
- public void updateState_whenAppListMoreThanThree_shouldDisplayTopThreeApps() {
- final List<RecentLocationAccesses.Access> accesses = createMockAccesses(6);
- doReturn(accesses).when(mRecentLocationApps).getAppListSorted();
- mController.displayPreference(mScreen);
- mController.updateState(mLayoutPreference);
-
- // The widget can display the top 3 apps from the list when there're more than 3.
- final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view);
- final ImageView appIconView1 = app1View.findViewById(R.id.app_icon);
- final TextView appTitle1 = app1View.findViewById(R.id.app_title);
-
- assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(appIconView1.getDrawable()).isNotNull();
- assertThat(appTitle1.getText()).isEqualTo("appTitle0");
-
- final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view);
- final ImageView appIconView2 = app2View.findViewById(R.id.app_icon);
- final TextView appTitle2 = app2View.findViewById(R.id.app_title);
-
- assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(appIconView2.getDrawable()).isNotNull();
- assertThat(appTitle2.getText()).isEqualTo("appTitle1");
-
- final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view);
- final ImageView appIconView3 = app3View.findViewById(R.id.app_icon);
- final TextView appTitle3 = app3View.findViewById(R.id.app_title);
-
- assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(appIconView3.getDrawable()).isNotNull();
- assertThat(appTitle3.getText()).isEqualTo("appTitle2");
- }
-
- private List<RecentLocationAccesses.Access> createMockAccesses(int count) {
- final List<RecentLocationAccesses.Access> accesses = new ArrayList<>();
- for (int i = 0; i < count; i++) {
- final Drawable icon = mock(Drawable.class);
- // Add mock accesses
- final RecentLocationAccesses.Access access = new RecentLocationAccesses.Access(
- "packageName", android.os.Process.myUserHandle(), icon,
- "appTitle" + i, "appSummary" + i, 1000 - i);
- accesses.add(access);
- }
- return accesses;
- }
}
diff --git a/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java
index 33109b0..d75bf4b 100644
--- a/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/privacy/AccessibilityUsagePreferenceControllerTest.java
@@ -65,8 +65,6 @@
@Test
public void getAvailabilityStatus_noEnabledServices_shouldReturnUnsupported() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true);
mAccessibilityManager.setEnabledAccessibilityServiceList(new ArrayList<>());
AccessibilityUsagePreferenceController controller =
new AccessibilityUsagePreferenceController(mContext, "test_key");
@@ -76,8 +74,6 @@
@Test
public void getAvailabilityStatus_enabledServices_shouldReturnAvailable() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "false", true);
mAccessibilityManager.setEnabledAccessibilityServiceList(
new ArrayList<>(Arrays.asList(new AccessibilityServiceInfo())));
AccessibilityUsagePreferenceController controller =
diff --git a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
index dc824ed..1335db5 100644
--- a/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/privacy/PermissionBarChartPreferenceControllerTest.java
@@ -117,144 +117,4 @@
// We have not yet set the property to show the Permissions Hub.
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
-
- @Test
- public void getAvailabilityStatus_permissionHubEnabled_shouldReturnAvailableUnsearchable() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
- "true", true);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
- }
-
- @Test
- public void displayPreference_shouldInitializeBarChart() {
- mController.displayPreference(mScreen);
-
- verify(mPreference).initializeBarChart(any(BarChartInfo.class));
- }
-
- @Test
- public void displayPreference_usageInfosSet_shouldSetBarViewInfos() {
- final RuntimePermissionUsageInfo info1 =
- new RuntimePermissionUsageInfo("permission 1", 10);
- mController.mOldUsageInfos.add(info1);
-
- mController.displayPreference(mScreen);
-
- verify(mPreference).setBarViewInfos(any(BarViewInfo[].class));
- verify(mPreference).initializeBarChart(any(BarChartInfo.class));
- }
-
- @Test
- public void onPermissionUsageResult_differentPermissionResultSet_shouldSetBarViewInfos() {
- final List<RuntimePermissionUsageInfo> infos1 = new ArrayList<>();
- final RuntimePermissionUsageInfo info1 =
- new RuntimePermissionUsageInfo("permission 1", 10);
- infos1.add(info1);
- mController.displayPreference(mScreen);
- mController.onPermissionUsageResult(infos1);
-
- verify(mPreference).setBarViewInfos(any(BarViewInfo[].class));
-
- final List<RuntimePermissionUsageInfo> infos2 = new ArrayList<>();
- final RuntimePermissionUsageInfo info2 =
- new RuntimePermissionUsageInfo("permission 2", 20);
- infos2.add(info2);
- mController.onPermissionUsageResult(infos2);
-
- verify(mPreference, times(2)).setBarViewInfos(any(BarViewInfo[].class));
- }
-
- @Test
- public void onPermissionUsageResult_samePermissionResultSet_shouldNotSetBarViewInfos() {
- final List<RuntimePermissionUsageInfo> mInfos = new ArrayList<>();
- final RuntimePermissionUsageInfo info1 =
- new RuntimePermissionUsageInfo("permission 1", 10);
- mInfos.add(info1);
- mController.displayPreference(mScreen);
- mController.onPermissionUsageResult(mInfos);
-
- mController.onPermissionUsageResult(mInfos);
-
- verify(mPreference, times(1)).setBarViewInfos(any(BarViewInfo[].class));
- }
-
- @Test
- public void onStart_usageInfosNotSetAndPermissionHubEnabled_shouldShowProgressBar() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
- "true", true);
- mController.displayPreference(mScreen);
-
- mController.onStart();
-
- verify(mFragment).setLoadingEnabled(true /* enabled */);
- verify(mPreference).updateLoadingState(true /* isLoading */);
- }
-
- @Test
- public void onStart_usageInfosSetAndPermissionHubEnabled_shouldNotUpdatePrefLoadingState() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
- "true", true);
- final RuntimePermissionUsageInfo info1 =
- new RuntimePermissionUsageInfo("permission 1", 10);
- mController.mOldUsageInfos.add(info1);
- mController.displayPreference(mScreen);
-
- mController.onStart();
-
- verify(mFragment).setLoadingEnabled(true /* enabled */);
- verify(mPreference).updateLoadingState(false /* isLoading */);
- }
-
- @Test
- public void onStart_permissionHubDisabled_shouldNotShowProgressBar() {
- DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY,
- Utils.PROPERTY_PERMISSIONS_HUB_ENABLED,
- "false", true);
-
- mController.onStart();
-
- verify(mFragment, never()).setLoadingEnabled(true /* enabled */);
- verify(mPreference, never()).updateLoadingState(true /* isLoading */);
- }
-
- @Test
- public void onPermissionUsageResult_shouldHideProgressBar() {
- final List<RuntimePermissionUsageInfo> infos1 = new ArrayList<>();
- final RuntimePermissionUsageInfo info1 =
- new RuntimePermissionUsageInfo("permission 1", 10);
- infos1.add(info1);
- mController.displayPreference(mScreen);
-
- mController.onPermissionUsageResult(infos1);
-
- verify(mFragment).setLoadingEnabled(false /* enabled */);
- verify(mPreference).updateLoadingState(false /* isLoading */);
- }
-
- @Test
- public void onPermissionUsageResult_shouldBeSorted() {
- final List<RuntimePermissionUsageInfo> infos = new ArrayList<>();
- infos.add(new RuntimePermissionUsageInfo(PHONE, 10));
- infos.add(new RuntimePermissionUsageInfo(LOCATION, 10));
- infos.add(new RuntimePermissionUsageInfo(CAMERA, 10));
- infos.add(new RuntimePermissionUsageInfo(SMS, 1));
- infos.add(new RuntimePermissionUsageInfo(MICROPHONE, 10));
- infos.add(new RuntimePermissionUsageInfo(CONTACTS, 42));
- infos.add(new RuntimePermissionUsageInfo(CALENDAR, 10));
- mController.displayPreference(mScreen);
-
- mController.onPermissionUsageResult(infos);
-
- assertThat(infos.get(0).getName()).isEqualTo(CONTACTS);
- assertThat(infos.get(1).getName()).isEqualTo(LOCATION);
- assertThat(infos.get(2).getName()).isEqualTo(MICROPHONE);
- assertThat(infos.get(3).getName()).isEqualTo(CAMERA);
- assertThat(infos.get(4).getName()).isEqualTo(CALENDAR);
- assertThat(infos.get(5).getName()).isEqualTo(PHONE);
- assertThat(infos.get(6).getName()).isEqualTo(SMS);
- }
}