summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorChing-Sung Li <chriscsli@google.com>2021-05-05 20:57:08 +0800
committerChing Sung Li <chriscsli@google.com>2021-05-17 00:06:46 +0000
commitcf80160fa3cc33c96d22895d04ffdb13bdbb1d3f (patch)
tree079fff75ed13579f698d3c49cf31e5cb2c5a685c /src/com/android
parentde5a0f04cb103811519a344b3cd05c32cd3b44ef (diff)
downloadThemePicker-cf80160fa3cc33c96d22895d04ffdb13bdbb1d3f.tar.gz
Supports themed icon options from Launcher
Adds the support of themed icon options from Launcher. Bug: 186590551 Test: Manual Change-Id: Ie64a410564a751ee8df37f032309033dfa435ae4
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/customization/model/themedicon/ThemedIconSwitchProvider.java67
-rw-r--r--src/com/android/customization/model/themedicon/ThemedIconUtils.java80
-rw-r--r--src/com/android/customization/model/themedicon/ThemedIconViewModel.kt32
3 files changed, 179 insertions, 0 deletions
diff --git a/src/com/android/customization/model/themedicon/ThemedIconSwitchProvider.java b/src/com/android/customization/model/themedicon/ThemedIconSwitchProvider.java
new file mode 100644
index 00000000..1a57223a
--- /dev/null
+++ b/src/com/android/customization/model/themedicon/ThemedIconSwitchProvider.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2021 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.customization.model.themedicon;
+
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.Cursor;
+
+import androidx.annotation.WorkerThread;
+
+/**
+ * Retrieves the themed icon switch by {@link ContentResolver}
+ */
+public class ThemedIconSwitchProvider {
+
+ private static final String GET_ICON_THEMED = "get_icon_themed";
+ private static final String SET_ICON_THEMED = "set_icon_themed";
+ private static final int ENABLED = 1;
+ private static final String COL_ICON_THEMED_VALUE = "boolean_value";
+
+ private final Context mContext;
+ private final ThemedIconUtils mThemedIconUtils;
+
+ public ThemedIconSwitchProvider(Context context, ThemedIconUtils themedIconUtils) {
+ mContext = context;
+ mThemedIconUtils = themedIconUtils;
+ }
+
+ public boolean isThemedIconAvailable() {
+ return mThemedIconUtils.isThemedIconAvailable();
+ }
+
+ @WorkerThread
+ protected boolean fetchThemedIconEnabled() {
+ ContentResolver contentResolver = mContext.getContentResolver();
+ try (Cursor cursor = contentResolver.query(
+ mThemedIconUtils.getUriForPath(GET_ICON_THEMED), /* projection= */
+ null, /* selection= */ null, /* selectionArgs= */ null, /* sortOrder= */ null)) {
+ if (cursor != null && cursor.moveToNext()) {
+ int themedIconEnabled = cursor.getInt(cursor.getColumnIndex(COL_ICON_THEMED_VALUE));
+ return themedIconEnabled == ENABLED;
+ }
+ }
+ return false;
+ }
+
+ protected int setThemedIconEnabled(boolean enabled) {
+ ContentValues values = new ContentValues();
+ values.put(COL_ICON_THEMED_VALUE, enabled);
+ return mContext.getContentResolver().update(mThemedIconUtils.getUriForPath(SET_ICON_THEMED),
+ values, /* where= */ null, /* selectionArgs= */ null);
+ }
+}
diff --git a/src/com/android/customization/model/themedicon/ThemedIconUtils.java b/src/com/android/customization/model/themedicon/ThemedIconUtils.java
new file mode 100644
index 00000000..8f1bdeea
--- /dev/null
+++ b/src/com/android/customization/model/themedicon/ThemedIconUtils.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2021 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.customization.model.themedicon;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ProviderInfo;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
+import android.text.TextUtils;
+
+/**
+ * Utility class for themed icon.
+ */
+public class ThemedIconUtils {
+
+ private final Context mContext;
+ private final String mProviderAuthority;
+
+ private ProviderInfo mProviderInfo;
+
+ public ThemedIconUtils(Context context, String authorityMetaKey) {
+ mContext = context;
+ Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER);
+ ResolveInfo resolveInfo = mContext.getPackageManager().resolveActivity(homeIntent,
+ PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA);
+
+ if (resolveInfo != null && resolveInfo.activityInfo.metaData != null) {
+ mProviderAuthority = resolveInfo.activityInfo.metaData.getString(authorityMetaKey);
+ } else {
+ mProviderAuthority = null;
+ }
+ mProviderInfo = TextUtils.isEmpty(mProviderAuthority) ? null :
+ mContext.getPackageManager().resolveContentProvider(mProviderAuthority, 0);
+ if (mProviderInfo != null && !TextUtils.isEmpty(mProviderInfo.readPermission)) {
+ if (mContext.checkSelfPermission(mProviderInfo.readPermission)
+ != PackageManager.PERMISSION_GRANTED) {
+ mProviderInfo = null;
+ }
+ }
+ }
+
+ /**
+ * Gets the Uri for this provider's authority with path information.
+ *
+ * @param path the path segment of {@link Uri}
+ * @return {@link Uri} with path information
+ */
+ Uri getUriForPath(String path) {
+ return new Uri.Builder()
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(mProviderInfo.authority)
+ .appendPath(path)
+ .build();
+ }
+
+ /**
+ * Returns if themed icon is available.
+ *
+ * @return true if themed icon feature is available, false otherwise.
+ */
+ boolean isThemedIconAvailable() {
+ return mProviderInfo != null;
+ }
+}
diff --git a/src/com/android/customization/model/themedicon/ThemedIconViewModel.kt b/src/com/android/customization/model/themedicon/ThemedIconViewModel.kt
new file mode 100644
index 00000000..f8906ff7
--- /dev/null
+++ b/src/com/android/customization/model/themedicon/ThemedIconViewModel.kt
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2021 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.customization.model.themedicon
+
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+
+/**
+ * ViewModel class to keep track of themed icon
+ */
+class ThemedIconViewModel : ViewModel() {
+
+ /**
+ * Flag for the themed icon enabled or not
+ */
+ val themedIconEnabled: MutableLiveData<Boolean> by lazy {
+ MutableLiveData<Boolean>()
+ }
+}