Commits

Anonymous committed 00f1f3d

Support intent policy

Comments (0)

Files changed (2)

res/xml/mmac_fragment.xml

             android:title="@string/mmac_restore_title"
             android:key="key_mmac_restore" />
 
+        <Preference
+            android:title="Reload Intent policy"
+            android:key="key_intent_reload" />
+
+        <Preference
+            android:title="Restore Intent policy"
+            android:key="key_intent_restore" />
+
     </PreferenceCategory>
 
 </PreferenceScreen>

src/com/android/seandroid_admin/MMACFragment.java

     private static final String KEY_MMAC_ENFORCING = "key_mmac_enforcing";
     private static final String KEY_MMAC_RELOAD = "key_mmac_reload";
     private static final String KEY_MMAC_RESTORE = "key_mmac_restore";
+    private static final String KEY_INTENT_RELOAD = "key_intent_reload";
+    private static final String KEY_INTENT_RESTORE = "key_intent_restore";
 
     private static final String MMAC_POLICY_FILE = "mac_permissions.xml";
+    private static final String INTENT_POLICY_FILE = "intent_mac.xml";
 
     private CheckBoxPreference mMMACenforceCheckbox;
-    private Preference mMMACreload;
-    private Preference mMMACrestore;
+    private Preference mMMACreload, mMMACrestore;
+    private Preference mIntentReload, mIntentRestore;
 
     private File mMMACpolicyFile = null;
+    private File mIntentPolicyFile = null;
 
     private String mMMACenforceCheckboxSummaryChecked;
     private String mMMACenforceCheckboxSummaryUnchecked;
             File extFileDir = mActivity.getExternalFilesDir(null);
             if (extFileDir != null) {
                 mMMACpolicyFile = new File(extFileDir, MMAC_POLICY_FILE);
+                mIntentPolicyFile = new File(extFileDir, INTENT_POLICY_FILE);
             }
 
             mMMACenforceCheckbox =
                     return false;
                 }
             });
+            
+            mIntentReload =
+                    getPreferenceScreen().findPreference(KEY_INTENT_RELOAD);
+            mIntentReload.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                @Override
+                public boolean onPreferenceClick(Preference preference) {
+                    Log.v(TAG, "Reload of Intent policy requested");
+                    try {
+                        byte[] policy = FileUtils.readFileToByteArray(mIntentPolicyFile);
+                        if (!mAdmin.mDPM.setCustomPolicyFile(mAdmin.mDeviceAdmin,
+                                DevicePolicyManager.INTENT_POLICY_FILE, policy)) {
+                            Toast.makeText(mActivity, "Unable to set policy", Toast.LENGTH_SHORT).show();
+                        } else {
+                            Toast.makeText(mActivity, "Success", Toast.LENGTH_SHORT).show();
+                        }
+                    } catch (IOException ioex) {
+                        Log.e(TAG, "Exception ocurred", ioex);
+                        Toast.makeText(mActivity, ioex.toString(), Toast.LENGTH_SHORT).show();
+                    }
+                    return false;
+                }
+            });
+
+            mIntentRestore =
+                    getPreferenceScreen().findPreference(KEY_INTENT_RESTORE);
+            mIntentRestore.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                @Override
+                public boolean onPreferenceClick(Preference preference) {
+                    Log.v(TAG, "Delete custom Intent policy requested");
+                    if (!mAdmin.mDPM.setCustomPolicyFile(mAdmin.mDeviceAdmin,
+                            DevicePolicyManager.INTENT_POLICY_FILE, null)) {
+                        Toast.makeText(mActivity, "Unable to remove custom policy", Toast.LENGTH_SHORT).show();
+                    } else {
+                        Toast.makeText(mActivity, "Success", Toast.LENGTH_SHORT).show();
+                    }
+                    return false;
+                }
+            });
         }
     }
 
             }
 
             mMMACrestore.setEnabled(true);
+            
+            mIntentReload.setEnabled(true);
+            if (mMMACpolicyFile != null) {
+                mIntentReload.setSummary(mIntentPolicyFile.getPath());
+            } else {
+                mIntentReload.setSummary(R.string.ext_storage_unavail);
+            }
+
+            mIntentRestore.setEnabled(true);
         }
     }