diff options
author | Lucas Dupin <dupin@google.com> | 2017-08-01 15:35:42 -0700 |
---|---|---|
committer | Lucas Dupin <dupin@google.com> | 2017-08-02 12:18:35 -0700 |
commit | 301b7ba1244a5f6375e71cc24cdc849367da4e67 (patch) | |
tree | d6f55ccd2fe101353692278a7335aa4a72d1b75c | |
parent | f6744e4cf5730af1fcf8c2d0e0bada443d2c9dff (diff) | |
download | android_packages_wallpapers_LivePicker-301b7ba1244a5f6375e71cc24cdc849367da4e67.tar.gz android_packages_wallpapers_LivePicker-301b7ba1244a5f6375e71cc24cdc849367da4e67.tar.bz2 android_packages_wallpapers_LivePicker-301b7ba1244a5f6375e71cc24cdc849367da4e67.zip |
Fix wallpaper settings crash
A wallpaper with invalid settings activity name in its meta-data
would crash LivePicker.
We're now trying to resolve the settings intent ahead of time
and not even showing the 'gear' if resolution fails.
Change-Id: I15faf466a78b65b4aedc063a5fbb29e852168a03
Fixes: 62398874
Test: Wrote a wallpaper with invalid meta-data, tried to open its settings.
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java index 6dab5c6..25ce3a4 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java @@ -27,6 +27,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.ServiceConnection; +import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.res.Resources.NotFoundException; import android.graphics.Rect; @@ -71,9 +72,9 @@ public class LiveWallpaperPreview extends Activity { private WallpaperManager mWallpaperManager; private WallpaperConnection mWallpaperConnection; - private String mSettings; private String mPackageName; private Intent mWallpaperIntent; + private Intent mSettingsIntent; private TextView mAttributionTitle; private TextView mAttributionSubtitle1; @@ -115,11 +116,23 @@ public class LiveWallpaperPreview extends Activity { mSpacer = findViewById(R.id.spacer); mLoading = findViewById(R.id.loading); - mSettings = info.getSettingsActivity(); mPackageName = info.getPackageName(); mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE) .setClassName(info.getPackageName(), info.getServiceName()); + final String settingsActivity = info.getSettingsActivity(); + if (settingsActivity != null) { + mSettingsIntent = new Intent(); + mSettingsIntent.setComponent(new ComponentName(mPackageName, settingsActivity)); + mSettingsIntent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true); + final PackageManager pm = getPackageManager(); + final ActivityInfo activityInfo = mSettingsIntent.resolveActivityInfo(pm, 0); + if (activityInfo == null) { + Log.e(LOG_TAG, "Couldn't find settings activity: " + settingsActivity); + mSettingsIntent = null; + } + } + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setActionBar(toolbar); getActionBar().setDisplayHomeAsUpEnabled(true); @@ -253,7 +266,7 @@ public class LiveWallpaperPreview extends Activity { @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_preview, menu); - menu.findItem(R.id.configure).setVisible(mSettings != null); + menu.findItem(R.id.configure).setVisible(mSettingsIntent != null); menu.findItem(R.id.set_wallpaper).getActionView().setOnClickListener( this::setLiveWallpaper); return super.onCreateOptionsMenu(menu); @@ -308,10 +321,7 @@ public class LiveWallpaperPreview extends Activity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.configure) { - Intent intent = new Intent(); - intent.setComponent(new ComponentName(mPackageName, mSettings)); - intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true); - startActivity(intent); + startActivity(mSettingsIntent); return true; } else if (id == R.id.set_wallpaper) { setLiveWallpaper(getWindow().getDecorView()); |