Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-CMFileManager: Commit

packages/apps/CMFileManager


Commit MetaInfo

Revision26fd0d7eac6ebc59a819ad9ba7772cab2420327e (tree)
Time2016-01-14 01:54:13
AuthorMartin Brabham <optedoblivion@cyng...>
CommiterMartin Brabham

Log Message

Bump target SDK version to 23

Implement new runtime permissions for STORAGE group

Change-Id: Ia32e5e279f8f4cc9f5cae33cc61cbd73ea2cf41b

Change Summary

Incremental Difference

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -21,8 +21,6 @@
2121
2222 <original-package android:name="com.cyanogenmod.filemanager" />
2323
24- <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21" />
25-
2624 <uses-feature android:name="android.software.leanback"
2725 android:required="false" />
2826
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -842,5 +842,6 @@
842842 <string name="welcome_msg">Welcome to the CyanogenMod file manager.\n\nThis app allows you to explore the file system and do operations that could break your device. To prevent damage, the app will start in a safe, low-privileged mode.\n\nYou can access the advanced, full-privileged mode via Settings. It\'s your responsibility to ensure that an operation doesn\'t break your system.\n\nThe CyanogenMod Team</string>
843843
844844 <string name="activity_not_found_exception">Couldn\'t find an app to open this file</string>
845+ <string name="storage_permissions_denied">Storage permissions denied!</string>
845846
846847 </resources>
--- a/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java
+++ b/src/com/cyanogenmod/filemanager/activities/NavigationActivity.java
@@ -26,6 +26,7 @@ import android.content.Context;
2626 import android.content.DialogInterface;
2727 import android.content.Intent;
2828 import android.content.IntentFilter;
29+import android.content.pm.PackageManager;
2930 import android.content.res.Configuration;
3031 import android.content.res.XmlResourceParser;
3132 import android.database.Cursor;
@@ -492,15 +493,47 @@ public class NavigationActivity extends Activity
492493
493494 private AsyncTask<Void, Void, Boolean> mBookmarksTask;
494495
495- /**
496- * {@inheritDoc}
497- */
498- @Override
499- protected void onCreate(Bundle state) {
496+ private static final int REQUEST_CODE_STORAGE_PERMS = 321;
497+ private boolean hasPermissions() {
498+ String permission = "android.permission.WRITE_EXTERNAL_STORAGE";
499+ int res = checkCallingOrSelfPermission(permission);
500+ return (res == PackageManager.PERMISSION_GRANTED);
501+ }
500502
501- if (DEBUG) {
502- Log.d(TAG, "NavigationActivity.onCreate"); //$NON-NLS-1$
503+ private void requestNecessaryPermissions() {
504+ String[] permissions = new String[] {
505+ "android.permission.WRITE_EXTERNAL_STORAGE"
506+ };
507+ requestPermissions(permissions, REQUEST_CODE_STORAGE_PERMS);
508+ }
509+
510+ @Override
511+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
512+ int[] grandResults) {
513+ boolean allowed = true;
514+ switch (requestCode) {
515+ case REQUEST_CODE_STORAGE_PERMS:
516+ for (int res : grandResults) {
517+ allowed = allowed && (res == PackageManager.PERMISSION_GRANTED);
518+ }
519+ break;
520+ default:
521+ allowed = false;
522+ break;
503523 }
524+ if (allowed) {
525+ finishOnCreate();
526+ if (mDrawerToggle != null) {
527+ mDrawerToggle.syncState();
528+ }
529+ } else {
530+ String text = getResources().getString(R.string.storage_permissions_denied);
531+ Toast.makeText(this, text, Toast.LENGTH_LONG).show();
532+ finish();
533+ }
534+ }
535+
536+ private void finishOnCreate() {
504537
505538 // Register the broadcast receiver
506539 IntentFilter filter = new IntentFilter();
@@ -624,8 +657,27 @@ public class NavigationActivity extends Activity
624657 EASY_MODE_ICONS.put(MimeTypeCategory.APP, getResources().getDrawable(R.drawable
625658 .ic_em_application));
626659
660+ }
661+
662+ /**
663+ * {@inheritDoc}
664+ */
665+ @Override
666+ protected void onCreate(Bundle state) {
667+
668+ if (DEBUG) {
669+ Log.d(TAG, "NavigationActivity.onCreate"); //$NON-NLS-1$
670+ }
671+
672+ if (!hasPermissions()) {
673+ requestNecessaryPermissions();
674+ } else {
675+ finishOnCreate();
676+ }
677+
627678 //Save state
628679 super.onCreate(state);
680+
629681 }
630682
631683 @Override
@@ -633,7 +685,8 @@ public class NavigationActivity extends Activity
633685 super.onStart();
634686
635687 // Check restrictions
636- if (!FileManagerApplication.checkRestrictSecondaryUsersAccess(this, mChRooted)) {
688+ if (!hasPermissions() ||
689+ !FileManagerApplication.checkRestrictSecondaryUsersAccess(this, mChRooted)) {
637690 return;
638691 }
639692
@@ -660,7 +713,9 @@ public class NavigationActivity extends Activity
660713 protected void onPostCreate(Bundle savedInstanceState) {
661714 super.onPostCreate(savedInstanceState);
662715 // Sync the toggle state after onRestoreInstanceState has occurred.
663- mDrawerToggle.syncState();
716+ if (mDrawerToggle != null) {
717+ mDrawerToggle.syncState();
718+ }
664719 }
665720
666721 /**
@@ -673,7 +728,9 @@ public class NavigationActivity extends Activity
673728 final boolean restore = TextUtils.isEmpty(navigateTo);
674729
675730 //Initialize navigation
676- initNavigation(this.mCurrentNavigationView, restore, intent);
731+ if (!hasPermissions()) {
732+ initNavigation(this.mCurrentNavigationView, restore, intent);
733+ }
677734
678735 //Check the intent action
679736 checkIntent(intent);
@@ -686,7 +743,9 @@ public class NavigationActivity extends Activity
686743 public void onConfigurationChanged(Configuration newConfig) {
687744 super.onConfigurationChanged(newConfig);
688745 onLayoutChanged();
689- mDrawerToggle.onConfigurationChanged(newConfig);
746+ if (mDrawerToggle != null ) {
747+ mDrawerToggle.onConfigurationChanged(newConfig);
748+ }
690749 }
691750
692751 /**
@@ -1805,12 +1864,12 @@ public class NavigationActivity extends Activity
18051864
18061865 @Override
18071866 public void onBackPressed() {
1808- if (mDrawerLayout.isDrawerOpen(Gravity.START)) {
1867+ if (mDrawerLayout != null && mDrawerLayout.isDrawerOpen(Gravity.START)) {
18091868 mDrawerLayout.closeDrawer(Gravity.START);
18101869 return;
18111870 }
18121871
1813- boolean upToParent = mHistory.size() > 0;
1872+ boolean upToParent = mHistory != null && mHistory.size() > 0;
18141873
18151874 if (mNeedsEasyMode && !isEasyModeVisible() && !upToParent) {
18161875 performShowEasyMode();
@@ -2556,9 +2615,11 @@ public class NavigationActivity extends Activity
25562615
25572616 private void recycle() {
25582617 // Recycle the navigation views
2559- int cc = this.mNavigationViews.length;
2560- for (int i = 0; i < cc; i++) {
2561- this.mNavigationViews[i].recycle();
2618+ if (mNavigationViews != null) {
2619+ int cc = this.mNavigationViews.length;
2620+ for (int i = 0; i < cc; i++) {
2621+ this.mNavigationViews[i].recycle();
2622+ }
25622623 }
25632624 try {
25642625 FileManagerApplication.destroyBackgroundConsole();
Show on old repository browser