Search in sources :

Example 6 with WallpaperInfo

use of android.app.WallpaperInfo in project platform_frameworks_base by android.

the class WallpaperManagerService method bindWallpaperComponentLocked.

boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force, boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
    if (DEBUG)
        Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
    // Has the component changed?
    if (!force) {
        if (wallpaper.connection != null) {
            if (wallpaper.wallpaperComponent == null) {
                if (componentName == null) {
                    if (DEBUG)
                        Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
                    // Still using default wallpaper.
                    return true;
                }
            } else if (wallpaper.wallpaperComponent.equals(componentName)) {
                // Changing to same wallpaper.
                if (DEBUG)
                    Slog.v(TAG, "same wallpaper");
                return true;
            }
        }
    }
    try {
        if (componentName == null) {
            componentName = WallpaperManager.getDefaultWallpaperComponent(mContext);
            if (componentName == null) {
                // Fall back to static image wallpaper
                componentName = mImageWallpaper;
                //return;
                if (DEBUG)
                    Slog.v(TAG, "Using image wallpaper");
            }
        }
        int serviceUserId = wallpaper.userId;
        ServiceInfo si = mIPackageManager.getServiceInfo(componentName, PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
        if (si == null) {
            // The wallpaper component we're trying to use doesn't exist
            Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
            return false;
        }
        if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
            String msg = "Selected service does not require " + android.Manifest.permission.BIND_WALLPAPER + ": " + componentName;
            if (fromUser) {
                throw new SecurityException(msg);
            }
            Slog.w(TAG, msg);
            return false;
        }
        WallpaperInfo wi = null;
        Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
        if (componentName != null && !componentName.equals(mImageWallpaper)) {
            // Make sure the selected service is actually a wallpaper service.
            List<ResolveInfo> ris = mIPackageManager.queryIntentServices(intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), PackageManager.GET_META_DATA, serviceUserId).getList();
            for (int i = 0; i < ris.size(); i++) {
                ServiceInfo rsi = ris.get(i).serviceInfo;
                if (rsi.name.equals(si.name) && rsi.packageName.equals(si.packageName)) {
                    try {
                        wi = new WallpaperInfo(mContext, ris.get(i));
                    } catch (XmlPullParserException e) {
                        if (fromUser) {
                            throw new IllegalArgumentException(e);
                        }
                        Slog.w(TAG, e);
                        return false;
                    } catch (IOException e) {
                        if (fromUser) {
                            throw new IllegalArgumentException(e);
                        }
                        Slog.w(TAG, e);
                        return false;
                    }
                    break;
                }
            }
            if (wi == null) {
                String msg = "Selected service is not a wallpaper: " + componentName;
                if (fromUser) {
                    throw new SecurityException(msg);
                }
                Slog.w(TAG, msg);
                return false;
            }
        }
        // Bind the service!
        if (DEBUG)
            Slog.v(TAG, "Binding to:" + componentName);
        WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
        intent.setComponent(componentName);
        intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.wallpaper_binding_label);
        intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(mContext, 0, Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), mContext.getText(com.android.internal.R.string.chooser_wallpaper)), 0, null, new UserHandle(serviceUserId)));
        if (!mContext.bindServiceAsUser(intent, newConn, Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, new UserHandle(serviceUserId))) {
            String msg = "Unable to bind service: " + componentName;
            if (fromUser) {
                throw new IllegalArgumentException(msg);
            }
            Slog.w(TAG, msg);
            return false;
        }
        if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
            detachWallpaperLocked(mLastWallpaper);
        }
        wallpaper.wallpaperComponent = componentName;
        wallpaper.connection = newConn;
        newConn.mReply = reply;
        try {
            if (wallpaper.userId == mCurrentUserId) {
                if (DEBUG)
                    Slog.v(TAG, "Adding window token: " + newConn.mToken);
                mIWindowManager.addWindowToken(newConn.mToken, WindowManager.LayoutParams.TYPE_WALLPAPER);
                mLastWallpaper = wallpaper;
            }
        } catch (RemoteException e) {
        }
    } catch (RemoteException e) {
        String msg = "Remote exception for " + componentName + "\n" + e;
        if (fromUser) {
            throw new IllegalArgumentException(msg);
        }
        Slog.w(TAG, msg);
        return false;
    }
    return true;
}
Also used : IWallpaperConnection(android.service.wallpaper.IWallpaperConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) Point(android.graphics.Point) ServiceInfo(android.content.pm.ServiceInfo) ResolveInfo(android.content.pm.ResolveInfo) UserHandle(android.os.UserHandle) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RemoteException(android.os.RemoteException) WallpaperInfo(android.app.WallpaperInfo)

Example 7 with WallpaperInfo

use of android.app.WallpaperInfo in project android_frameworks_base by DirtyUnicorns.

the class WallpaperManagerService method bindWallpaperComponentLocked.

boolean bindWallpaperComponentLocked(ComponentName componentName, boolean force, boolean fromUser, WallpaperData wallpaper, IRemoteCallback reply) {
    if (DEBUG)
        Slog.v(TAG, "bindWallpaperComponentLocked: componentName=" + componentName);
    // Has the component changed?
    if (!force) {
        if (wallpaper.connection != null) {
            if (wallpaper.wallpaperComponent == null) {
                if (componentName == null) {
                    if (DEBUG)
                        Slog.v(TAG, "bindWallpaperComponentLocked: still using default");
                    // Still using default wallpaper.
                    return true;
                }
            } else if (wallpaper.wallpaperComponent.equals(componentName)) {
                // Changing to same wallpaper.
                if (DEBUG)
                    Slog.v(TAG, "same wallpaper");
                return true;
            }
        }
    }
    try {
        if (componentName == null) {
            componentName = WallpaperManager.getDefaultWallpaperComponent(mContext);
            if (componentName == null) {
                // Fall back to static image wallpaper
                componentName = mImageWallpaper;
                //return;
                if (DEBUG)
                    Slog.v(TAG, "Using image wallpaper");
            }
        }
        int serviceUserId = wallpaper.userId;
        ServiceInfo si = mIPackageManager.getServiceInfo(componentName, PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS, serviceUserId);
        if (si == null) {
            // The wallpaper component we're trying to use doesn't exist
            Slog.w(TAG, "Attempted wallpaper " + componentName + " is unavailable");
            return false;
        }
        if (!android.Manifest.permission.BIND_WALLPAPER.equals(si.permission)) {
            String msg = "Selected service does not require " + android.Manifest.permission.BIND_WALLPAPER + ": " + componentName;
            if (fromUser) {
                throw new SecurityException(msg);
            }
            Slog.w(TAG, msg);
            return false;
        }
        WallpaperInfo wi = null;
        Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
        if (componentName != null && !componentName.equals(mImageWallpaper)) {
            // Make sure the selected service is actually a wallpaper service.
            List<ResolveInfo> ris = mIPackageManager.queryIntentServices(intent, intent.resolveTypeIfNeeded(mContext.getContentResolver()), PackageManager.GET_META_DATA, serviceUserId).getList();
            for (int i = 0; i < ris.size(); i++) {
                ServiceInfo rsi = ris.get(i).serviceInfo;
                if (rsi.name.equals(si.name) && rsi.packageName.equals(si.packageName)) {
                    try {
                        wi = new WallpaperInfo(mContext, ris.get(i));
                    } catch (XmlPullParserException e) {
                        if (fromUser) {
                            throw new IllegalArgumentException(e);
                        }
                        Slog.w(TAG, e);
                        return false;
                    } catch (IOException e) {
                        if (fromUser) {
                            throw new IllegalArgumentException(e);
                        }
                        Slog.w(TAG, e);
                        return false;
                    }
                    break;
                }
            }
            if (wi == null) {
                String msg = "Selected service is not a wallpaper: " + componentName;
                if (fromUser) {
                    throw new SecurityException(msg);
                }
                Slog.w(TAG, msg);
                return false;
            }
        }
        // Bind the service!
        if (DEBUG)
            Slog.v(TAG, "Binding to:" + componentName);
        WallpaperConnection newConn = new WallpaperConnection(wi, wallpaper);
        intent.setComponent(componentName);
        intent.putExtra(Intent.EXTRA_CLIENT_LABEL, com.android.internal.R.string.wallpaper_binding_label);
        intent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivityAsUser(mContext, 0, Intent.createChooser(new Intent(Intent.ACTION_SET_WALLPAPER), mContext.getText(com.android.internal.R.string.chooser_wallpaper)), 0, null, new UserHandle(serviceUserId)));
        if (!mContext.bindServiceAsUser(intent, newConn, Context.BIND_AUTO_CREATE | Context.BIND_SHOWING_UI | Context.BIND_FOREGROUND_SERVICE_WHILE_AWAKE, new UserHandle(serviceUserId))) {
            String msg = "Unable to bind service: " + componentName;
            if (fromUser) {
                throw new IllegalArgumentException(msg);
            }
            Slog.w(TAG, msg);
            return false;
        }
        if (wallpaper.userId == mCurrentUserId && mLastWallpaper != null) {
            detachWallpaperLocked(mLastWallpaper);
        }
        wallpaper.wallpaperComponent = componentName;
        wallpaper.connection = newConn;
        newConn.mReply = reply;
        try {
            if (wallpaper.userId == mCurrentUserId) {
                if (DEBUG)
                    Slog.v(TAG, "Adding window token: " + newConn.mToken);
                mIWindowManager.addWindowToken(newConn.mToken, WindowManager.LayoutParams.TYPE_WALLPAPER);
                mLastWallpaper = wallpaper;
            }
        } catch (RemoteException e) {
        }
    } catch (RemoteException e) {
        String msg = "Remote exception for " + componentName + "\n" + e;
        if (fromUser) {
            throw new IllegalArgumentException(msg);
        }
        Slog.w(TAG, msg);
        return false;
    }
    return true;
}
Also used : IWallpaperConnection(android.service.wallpaper.IWallpaperConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) Point(android.graphics.Point) ServiceInfo(android.content.pm.ServiceInfo) ResolveInfo(android.content.pm.ResolveInfo) UserHandle(android.os.UserHandle) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RemoteException(android.os.RemoteException) WallpaperInfo(android.app.WallpaperInfo)

Aggregations

WallpaperInfo (android.app.WallpaperInfo)7 Intent (android.content.Intent)6 ResolveInfo (android.content.pm.ResolveInfo)6 PendingIntent (android.app.PendingIntent)5 ServiceInfo (android.content.pm.ServiceInfo)5 RemoteException (android.os.RemoteException)5 UserHandle (android.os.UserHandle)5 IWallpaperConnection (android.service.wallpaper.IWallpaperConnection)5 IOException (java.io.IOException)5 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)5 Point (android.graphics.Point)4 RequiresPermission (android.annotation.RequiresPermission)1 SystemApi (android.annotation.SystemApi)1 WallpaperManager (android.app.WallpaperManager)1 Uri (android.net.Uri)1 Implementation (org.robolectric.annotation.Implementation)1