diff options
| author | zhuw <zhuw@codeaurora.org> | 2016-08-23 18:42:01 +0800 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-08-30 19:12:28 -0700 |
| commit | 50ebf4bb05538434e5676fb4f8ffc58fdc1d853f (patch) | |
| tree | ad071be6c5451aa51d76bbc3f4dadd877836b1fa /src | |
| parent | 835ee3d00a1c48492224ec76247e91e98b128339 (diff) | |
| download | android_packages_apps_Gallery2-50ebf4bb05538434e5676fb4f8ffc58fdc1d853f.tar.gz android_packages_apps_Gallery2-50ebf4bb05538434e5676fb4f8ffc58fdc1d853f.tar.bz2 android_packages_apps_Gallery2-50ebf4bb05538434e5676fb4f8ffc58fdc1d853f.zip | |
SnapdragonGallery: Fix crash after deny permission in video app
1. Create new abstract activity to get permissions.
2. Modify GalleryActivity and MovieActivity inherits it.
3. Modify the process of MovieActivity to fit the changes of getting permissions.
Change-Id: I41bac4bd7be3ee6cc4e8d2696376a873acfed2f5
CRs-Fixed: 1008108
Diffstat (limited to 'src')
5 files changed, 217 insertions, 86 deletions
diff --git a/src/com/android/gallery3d/app/AbstractGalleryActivity.java b/src/com/android/gallery3d/app/AbstractGalleryActivity.java index f9b0fd6dc..709151a1a 100644 --- a/src/com/android/gallery3d/app/AbstractGalleryActivity.java +++ b/src/com/android/gallery3d/app/AbstractGalleryActivity.java @@ -51,7 +51,8 @@ import com.android.photos.data.GalleryBitmapPool; import java.io.FileNotFoundException; -public class AbstractGalleryActivity extends Activity implements GalleryContext { +public abstract class AbstractGalleryActivity extends AbstractPermissionActivity + implements GalleryContext { private static final String TAG = "AbstractGalleryActivity"; private GLRootView mGLRootView; private StateManager mStateManager; diff --git a/src/com/android/gallery3d/app/AbstractPermissionActivity.java b/src/com/android/gallery3d/app/AbstractPermissionActivity.java new file mode 100644 index 000000000..e4fc95372 --- /dev/null +++ b/src/com/android/gallery3d/app/AbstractPermissionActivity.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.android.gallery3d.app; + +import android.Manifest; +import android.app.Activity; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; + +import java.util.ArrayList; + +public abstract class AbstractPermissionActivity extends Activity { + + public static final int PERMISSION_REQUEST_STORAGE = 1; + private boolean permissionGranted = false; + + protected abstract void onGetPermissionsSuccess(); + protected abstract void onGetPermissionsFailure(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestStoragePermission(); + } + + private void requestStoragePermission() { + String[] permissions = { + Manifest.permission.WRITE_EXTERNAL_STORAGE, + Manifest.permission.READ_EXTERNAL_STORAGE + }; + requestPermission(permissions, PERMISSION_REQUEST_STORAGE); + } + + protected void requestPermission(String[] permissions, int requestCode) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + permissionGranted = true; + return; + } + + boolean needRequest = false; + ArrayList<String> permissionList = new ArrayList<String>(); + for (String permission : permissions) { + if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { + permissionList.add(permission); + needRequest = true; + } + } + + if (needRequest) { + int count = permissionList.size(); + if (count > 0) { + String[] permissionArray = new String[count]; + for (int i = 0; i < count; i++) { + permissionArray[i] = permissionList.get(i); + } + + requestPermissions(permissionArray, requestCode); + } + } + permissionGranted = !needRequest; + } + + private boolean checkPermissionGrantResults(int[] grantResults) { + for (int result : grantResults) { + if (result != PackageManager.PERMISSION_GRANTED) { + return false; + } + } + return true; + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, + int[] grantResults) { + permissionGranted = checkPermissionGrantResults(grantResults); + switch (requestCode) { + case PERMISSION_REQUEST_STORAGE: { + if (permissionGranted) { + onGetPermissionsSuccess(); + } else { + onGetPermissionsFailure(); + } + } + } + } + + protected boolean isPermissionGranted() { + return permissionGranted; + } +} diff --git a/src/com/android/gallery3d/app/GalleryActivity.java b/src/com/android/gallery3d/app/GalleryActivity.java index 7a4e5db28..93ac5a4bc 100755 --- a/src/com/android/gallery3d/app/GalleryActivity.java +++ b/src/com/android/gallery3d/app/GalleryActivity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, The Linux Foundation. All rights reserved. + * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. * Not a Contribution * * Copyright (C) 2009 The Android Open Source Project @@ -123,8 +123,7 @@ public final class GalleryActivity extends AbstractGalleryActivity implements On initView(); mSavedInstanceState = savedInstanceState; - - if (!needRequestStoragePermission()) { + if (isPermissionGranted()) { init(); } } @@ -144,57 +143,13 @@ public final class GalleryActivity extends AbstractGalleryActivity implements On } @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], - int[] grantResults) { - switch (requestCode) { - case PERMISSION_REQUEST_STORAGE: { - if (checkPermissionGrantResults(grantResults)) { - init(); - } else { - finish(); - } - } - } - } - - private boolean needRequestStoragePermission() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false; - - boolean needRequest = false; - String[] permissions = { - Manifest.permission.WRITE_EXTERNAL_STORAGE, - Manifest.permission.READ_EXTERNAL_STORAGE - }; - ArrayList<String> permissionList = new ArrayList<String>(); - for (String permission : permissions) { - if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) { - permissionList.add(permission); - needRequest = true; - } - } - - if (needRequest) { - int count = permissionList.size(); - if (count > 0) { - String[] permissionArray = new String[count]; - for (int i = 0; i < count; i++) { - permissionArray[i] = permissionList.get(i); - } - - requestPermissions(permissionArray, PERMISSION_REQUEST_STORAGE); - } - } - - return needRequest; + protected void onGetPermissionsSuccess() { + init(); } - private boolean checkPermissionGrantResults(int[] grantResults) { - for (int result : grantResults) { - if (result != PackageManager.PERMISSION_GRANTED) { - return false; - } - } - return true; + @Override + protected void onGetPermissionsFailure() { + finish(); } private static class ActionItem { diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java index cbea7b303..150b3807f 100644 --- a/src/com/android/gallery3d/app/MovieActivity.java +++ b/src/com/android/gallery3d/app/MovieActivity.java @@ -19,7 +19,6 @@ package com.android.gallery3d.app; import android.annotation.TargetApi; import android.app.ActionBar; import android.app.ActionBar.OnMenuVisibilityListener; -import android.app.Activity; import android.app.AlertDialog; import android.app.KeyguardManager; import android.bluetooth.BluetoothClass; @@ -86,7 +85,7 @@ import android.bluetooth.BluetoothProfile; * to set the action bar logo so the playback process looks more seamlessly integrated with * the original activity. */ -public class MovieActivity extends Activity { +public class MovieActivity extends AbstractPermissionActivity { @SuppressWarnings("unused") private static final String TAG = "MovieActivity"; private static final boolean LOG = true; @@ -126,6 +125,7 @@ public class MovieActivity extends Activity { private IMovieItem mMovieItem; private IActivityHooker mMovieHooker; private KeyguardManager mKeyguardManager; + private Bundle mSavedInstanceState; private boolean mResumed = false; private boolean mControlResumed = false; @@ -186,14 +186,29 @@ public class MovieActivity extends Activity { Intent intent = getIntent(); - mMovieHooker = ExtensionHelper.getHooker(this); - initMovieInfo(intent); - initializeActionBar(intent); mFinishOnCompletion = intent.getBooleanExtra( MediaStore.EXTRA_FINISH_ON_COMPLETION, true); mPrefs = getSharedPreferences(getApplicationContext().getPackageName(), Context.MODE_PRIVATE); + mSavedInstanceState = savedInstanceState; + if (isPermissionGranted()) { + init(intent, rootView, savedInstanceState); + } + + // DRM validation +// Uri original = intent.getData(); +// String mimeType = intent.getType(); +// String filepath = DrmHelper.getFilePath(this, original); +// if (DrmHelper.isDrmFile(filepath)) { +// if (!DrmHelper.validateLicense(this, filepath, mimeType)) { +// finish(); +// } +// } + } + + private void init(Intent intent, View rootView, Bundle savedInstanceState) { + initMovieInfo(intent); mPlayer = new MoviePlayer(rootView, this, mMovieItem, savedInstanceState, !mFinishOnCompletion) { @Override @@ -223,12 +238,7 @@ public class MovieActivity extends Activity { // We set the background in the theme to have the launching animation. // But for the performance (and battery), we remove the background here. win.setBackgroundDrawable(null); - mMovieHooker.init(this, intent); - mMovieHooker.setParameter(null, mPlayer.getMoviePlayerExt()); - mMovieHooker.setParameter(null, mMovieItem); - mMovieHooker.setParameter(null, mPlayer.getVideoSurface()); - mMovieHooker.onCreate(savedInstanceState); - + initMovieHooker(intent, savedInstanceState); // Determine available/supported effects final Descriptor[] effects = AudioEffect.queryEffects(); for (final Descriptor effect : effects) { @@ -246,16 +256,29 @@ public class MovieActivity extends Activity { initEffects(mp.getAudioSessionId()); } }); + } - // DRM validation -// Uri original = intent.getData(); -// String mimeType = intent.getType(); -// String filepath = DrmHelper.getFilePath(this, original); -// if (DrmHelper.isDrmFile(filepath)) { -// if (!DrmHelper.validateLicense(this, filepath, mimeType)) { -// finish(); -// } -// } + private void initMovieHooker(Intent intent, Bundle savedInstanceState) { + mMovieHooker = ExtensionHelper.getHooker(this); + mMovieHooker.init(this, intent); + mMovieHooker.setParameter(null, mPlayer.getMoviePlayerExt()); + mMovieHooker.setParameter(null, mMovieItem); + mMovieHooker.setParameter(null, mPlayer.getVideoSurface()); + mMovieHooker.onCreate(savedInstanceState); + } + + + @Override + protected void onGetPermissionsSuccess() { + init(getIntent(), findViewById(R.id.movie_view_root), mSavedInstanceState); + mPlayer.requestAudioFocus(); + mMovieHooker.onStart(); + registerScreenReceiver(); + } + + @Override + protected void onGetPermissionsFailure() { + finish(); } private void setActionBarLogoFromIntent(Intent intent) { @@ -337,7 +360,6 @@ public class MovieActivity extends Activity { // share provider is singleton, we should refresh our history file. mShareProvider.setShareHistoryFileName(SHARE_HISTORY_FILE); } - refreshShareProvider(mMovieItem); final MenuItem mi = menu.add(R.string.audio_effects); mi.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @@ -347,14 +369,19 @@ public class MovieActivity extends Activity { return true; } }); - mMovieHooker.onCreateOptionsMenu(menu); + if (isPermissionGranted()) { + refreshShareProvider(mMovieItem); + mMovieHooker.onCreateOptionsMenu(menu); + } return true; } @Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - mMovieHooker.onPrepareOptionsMenu(menu); + if (mMovieHooker != null) { + mMovieHooker.onPrepareOptionsMenu(menu); + } // if (mMovieItem != null // && !DrmHelper.isShareableDrmFile(DrmHelper.getFilePath(this, @@ -550,6 +577,10 @@ public class MovieActivity extends Activity { @Override public void onStart() { + if (!isPermissionGranted()) { + super.onStart(); + return; + } mPlayer.requestAudioFocus(); super.onStart(); mMovieHooker.onStart(); @@ -558,6 +589,10 @@ public class MovieActivity extends Activity { @Override protected void onStop() { + if (!isPermissionGranted()) { + super.onStop(); + return; + } mPlayer.abandonAudioFocus(); super.onStop(); if (mControlResumed && mPlayer != null) { @@ -570,6 +605,10 @@ public class MovieActivity extends Activity { @Override public void onPause() { + if (!isPermissionGranted()) { + super.onPause(); + return; + } // Audio track will be deallocated for local video playback, // thus recycle effect here. releaseEffects(); @@ -588,8 +627,6 @@ public class MovieActivity extends Activity { @Override public void onResume() { - invalidateOptionsMenu(); - if ((mVirtualizerSupported) || (mBassBoostSupported)) { final IntentFilter intentFilter = new IntentFilter(Intent.ACTION_HEADSET_PLUG); intentFilter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED); @@ -599,14 +636,19 @@ public class MovieActivity extends Activity { } mResumed = true; - if (!isKeyguardLocked() && !mControlResumed && mPlayer != null) { - mPlayer.onResume(); - mControlResumed = true; - //initEffects(mPlayer.getAudioSessionId()); + if (isPermissionGranted()) { + invalidateOptionsMenu(); + if (!isKeyguardLocked() && !mControlResumed && mPlayer != null) { + mPlayer.onResume(); + mControlResumed = true; + //initEffects(mPlayer.getAudioSessionId()); + } + enhanceActionBar(); + super.onResume(); + mMovieHooker.onResume(); + } else { + super.onResume(); } - enhanceActionBar(); - super.onResume(); - mMovieHooker.onResume(); } @Override @@ -614,7 +656,9 @@ public class MovieActivity extends Activity { super.onConfigurationChanged(newConfig); if(this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE || this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - mPlayer.setDefaultScreenMode(); + if(mPlayer != null) { + mPlayer.setDefaultScreenMode(); + } } } @@ -635,6 +679,10 @@ public class MovieActivity extends Activity { @Override public void onDestroy() { + if (!isPermissionGranted()) { + super.onDestroy(); + return; + } releaseEffects(); mPlayer.onDestroy(); super.onDestroy(); diff --git a/src/com/android/gallery3d/app/PickerActivity.java b/src/com/android/gallery3d/app/PickerActivity.java index 09ce203ee..78d0f253e 100644 --- a/src/com/android/gallery3d/app/PickerActivity.java +++ b/src/com/android/gallery3d/app/PickerActivity.java @@ -80,4 +80,14 @@ public class PickerActivity extends AbstractGalleryActivity public void onClick(View v) { if (v.getId() == R.id.cancel) finish(); } + + @Override + protected void onGetPermissionsSuccess() { + + } + + @Override + protected void onGetPermissionsFailure() { + + } } |
