Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50166894 authored by vadimt's avatar vadimt Committed by Automerger Merge Worker
Browse files

Merging from ub-launcher3-master @ build 6327709 am: 0997905b am: 7e3d6cbd

Change-Id: Ibe4d68378d43e91a39de36964e8a007eac8f6d06
parents 1ad86cfb 7e3d6cbd
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -21,11 +21,6 @@
    <!-- Authority of a provider in System UI that will provide preview info for available clockfaces. -->
    <string name="clocks_provider_authority" translatable="false">com.android.keyguard.clock</string>

    <!--Name of metadata in the main launcher Activity which values contains the authority
        corresponding to a ContentProvider in launcher to provide available grids and
        allow for changing them -->
    <string name="grid_control_metadata_name" translatable="false">com.android.launcher3.grid.control</string>

    <string name="launcher_overlayable_package" translatable="false">com.android.launcher3</string>

    <!-- List of packages whose icons are used to preview the icon shape for a theme. These are
+11 −48
Original line number Diff line number Diff line
@@ -18,13 +18,8 @@ package com.android.customization.model.grid;
import android.content.ContentResolver;
import android.content.ContentValues;
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.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Pair;
@@ -36,6 +31,7 @@ import androidx.annotation.WorkerThread;
import com.android.customization.model.ResourceConstants;
import com.android.systemui.shared.system.SurfaceViewRequestUtils;
import com.android.wallpaper.R;
import com.android.wallpaper.util.PreviewUtils;

import com.bumptech.glide.Glide;

@@ -57,33 +53,20 @@ public class LauncherGridOptionsProvider {
    private static final String COL_PREVIEW_COUNT = "preview_count";
    private static final String COL_IS_DEFAULT = "is_default";

    private static final String METHOD_GET_PREVIEW = "get_preview";
    private static final String METADATA_KEY_PREVIEW_VERSION = "preview_version";

    private final Context mContext;
    private final String mGridProviderAuthority;
    private final ProviderInfo mProviderInfo;
    private final PreviewUtils mPreviewUtils;
    private List<GridOption> mOptions;
    private String mVersion;

    public LauncherGridOptionsProvider(Context context, String authorityMetadataKey) {
        mPreviewUtils = new PreviewUtils(context, authorityMetadataKey);
        mContext = context;
        Intent homeIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);

        ResolveInfo info = context.getPackageManager().resolveActivity(homeIntent,
                PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA);
        if (info != null && info.activityInfo != null && info.activityInfo.metaData != null) {
            mGridProviderAuthority = info.activityInfo.metaData.getString(authorityMetadataKey);
        } else {
            mGridProviderAuthority = null;
        }
        // TODO: check permissions if needed
        mProviderInfo = TextUtils.isEmpty(mGridProviderAuthority) ? null
                : mContext.getPackageManager().resolveContentProvider(mGridProviderAuthority, 0);
    }

    boolean areGridsAvailable() {
        return mProviderInfo != null;
        return mPreviewUtils.supportsPreview();
    }

    boolean usesSurfaceView() {
@@ -104,15 +87,11 @@ public class LauncherGridOptionsProvider {
        if (mOptions != null && !reload) {
            return Pair.create(mOptions, mVersion);
        }
        Uri optionsUri = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority(mProviderInfo.authority)
                .appendPath(LIST_OPTIONS)
                .build();
        ContentResolver resolver = mContext.getContentResolver();
        String iconPath = mContext.getResources().getString(Resources.getSystem().getIdentifier(
                ResourceConstants.CONFIG_ICON_MASK, "string", ResourceConstants.ANDROID_PACKAGE));
        try (Cursor c = resolver.query(optionsUri, null, null, null, null)) {
        try (Cursor c = resolver.query(mPreviewUtils.getUri(LIST_OPTIONS), null, null, null,
                null)) {
            mVersion = c.getExtras().getString(METADATA_KEY_PREVIEW_VERSION);
            mOptions = new ArrayList<>();
            while(c.moveToNext()) {
@@ -121,15 +100,9 @@ public class LauncherGridOptionsProvider {
                int cols = c.getInt(c.getColumnIndex(COL_COLS));
                int previewCount = c.getInt(c.getColumnIndex(COL_PREVIEW_COUNT));
                boolean isSet = Boolean.valueOf(c.getString(c.getColumnIndex(COL_IS_DEFAULT)));
                Uri preview = new Uri.Builder()
                        .scheme(ContentResolver.SCHEME_CONTENT)
                        .authority(mProviderInfo.authority)
                        .appendPath(PREVIEW)
                        .appendPath(name)
                        .build();
                String title = mContext.getString(R.string.grid_title_pattern, cols, rows);
                mOptions.add(new GridOption(title, name, isSet, rows, cols, preview, previewCount,
                        iconPath));
                mOptions.add(new GridOption(title, name, isSet, rows, cols,
                        mPreviewUtils.getUri(PREVIEW), previewCount, iconPath));
            }
            Glide.get(mContext).clearDiskCache();
        } catch (Exception e) {
@@ -146,24 +119,14 @@ public class LauncherGridOptionsProvider {
     *                  {@link SurfaceViewRequestUtils#createSurfaceBundle(SurfaceView)}.
     */
    void renderPreview(String name, Bundle bundle) {
        Uri preview = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority(mProviderInfo.authority)
                .appendPath(PREVIEW)
                .appendPath(name)
                .build();
        bundle.putString("name", name);
        mContext.getContentResolver().call(preview, METHOD_GET_PREVIEW, null, bundle);
        mPreviewUtils.renderPreview(bundle);
    }

    int applyGrid(String name) {
        Uri updateDefaultUri = new Uri.Builder()
                .scheme(ContentResolver.SCHEME_CONTENT)
                .authority(mProviderInfo.authority)
                .appendPath(DEFAULT_GRID)
                .build();
        ContentValues values = new ContentValues();
        values.put("name", name);
        return mContext.getContentResolver().update(updateDefaultUri, values, null, null);
        return mContext.getContentResolver().update(mPreviewUtils.getUri(DEFAULT_GRID), values,
                null, null);
    }
}