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

Commit 5aeef581 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Add support for partner customization.

Traditionally Launcher workspace customization is offered through
overlays at build time, but we don't have access to partner-specific
customization at build time.  To solve this, this adds a new
"partner-folder" tag which points at an XML resource provided by
an external package.

The external package XML can't depend on the binary XML attributes
defined by Launcher3, so we switch to using manual string-based
attribute lookups.  Partners can also provide extra wallpapers.

When a folder only results in a single item, promote that item into
the folder location instead of deleting completely.

Bug: 13340779
Change-Id: Ide558288bef4113565f288b700d8245055c0fee9
parent 76ac344c
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -887,14 +887,24 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
    }

    private ArrayList<ResourceWallpaperInfo> findBundledWallpapers() {
        ArrayList<ResourceWallpaperInfo> bundledWallpapers =
                new ArrayList<ResourceWallpaperInfo>(24);
        final PackageManager pm = getPackageManager();
        final ArrayList<ResourceWallpaperInfo> bundled = new ArrayList<ResourceWallpaperInfo>(24);

        Partner partner = Partner.get(pm);
        if (partner != null) {
            final Resources partnerRes = partner.getResources();
            final int resId = partnerRes.getIdentifier(Partner.RESOURCE_WALLPAPERS, "array",
                    partner.getPackageName());
            if (resId != 0) {
                addWallpapers(bundled, partnerRes, partner.getPackageName(), resId);
            }
        }

        Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId();
        if (r != null) {
            try {
                Resources wallpaperRes = getPackageManager().getResourcesForApplication(r.first);
                bundledWallpapers = addWallpapers(wallpaperRes, r.first.packageName, r.second);
                addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second);
            } catch (PackageManager.NameNotFoundException e) {
            }
        }
@@ -903,10 +913,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            ResourceWallpaperInfo defaultWallpaperInfo = getPreKKDefaultWallpaperInfo();
            if (defaultWallpaperInfo != null) {
                bundledWallpapers.add(0, defaultWallpaperInfo);
                bundled.add(0, defaultWallpaperInfo);
            }
        }
        return bundledWallpapers;
        return bundled;
    }

    private boolean writeImageToFileAsJpeg(File f, Bitmap b) {
@@ -998,10 +1008,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
        }
    }

    private ArrayList<ResourceWallpaperInfo> addWallpapers(
            Resources res, String packageName, int listResId) {
        ArrayList<ResourceWallpaperInfo> bundledWallpapers =
                new ArrayList<ResourceWallpaperInfo>(24);
    private void addWallpapers(ArrayList<ResourceWallpaperInfo> known, Resources res,
            String packageName, int listResId) {
        final String[] extras = res.getStringArray(listResId);
        for (String extra : extras) {
            int resId = res.getIdentifier(extra, "drawable", packageName);
@@ -1011,14 +1019,13 @@ public class WallpaperPickerActivity extends WallpaperCropActivity {
                if (thumbRes != 0) {
                    ResourceWallpaperInfo wallpaperInfo =
                            new ResourceWallpaperInfo(res, resId, res.getDrawable(thumbRes));
                    bundledWallpapers.add(wallpaperInfo);
                    known.add(wallpaperInfo);
                    // Log.d(TAG, "add: [" + packageName + "]: " + extra + " (" + res + ")");
                }
            } else {
                Log.e(TAG, "Couldn't find wallpaper " + extra);
            }
        }
        return bundledWallpapers;
    }

    public CropView getCropView() {
+181 −105

File changed.

Preview size limit exceeded, changes collapsed.

+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.launcher3;

import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.util.Log;

/**
 * Utilities to discover and interact with partner customizations. There can
 * only be one set of customizations on a device, and it must be bundled with
 * the system.
 */
public class Partner {
    private static final String TAG = "Partner";

    /** Marker action used to discover partner */
    private static final String
            ACTION_PARTNER_CUSTOMIZATION = "com.android.launcher3.action.PARTNER_CUSTOMIZATION";

    public static final String RESOURCE_FOLDER = "partner_folder";
    public static final String RESOURCE_WALLPAPERS = "partner_wallpapers";

    private static boolean sSearched = false;
    private static Partner sPartner;

    /**
     * Find and return partner details, or {@code null} if none exists.
     */
    public static synchronized Partner get(PackageManager pm) {
        if (!sSearched) {
            final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION);
            for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
                if (info.activityInfo != null &&
                        (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    final String packageName = info.activityInfo.packageName;
                    try {
                        final Resources res = pm.getResourcesForApplication(packageName);
                        sPartner = new Partner(packageName, res);
                        break;
                    } catch (NameNotFoundException e) {
                        Log.w(TAG, "Failed to find resources for " + packageName);
                    }
                }
            }
            sSearched = true;
        }
        return sPartner;
    }

    private final String mPackageName;
    private final Resources mResources;

    private Partner(String packageName, Resources res) {
        mPackageName = packageName;
        mResources = res;
    }

    public String getPackageName() {
        return mPackageName;
    }

    public Resources getResources() {
        return mResources;
    }
}