Commits

Joman Chu  committed 8b67d7c

Support setting MMAC types file

  • Participants
  • Parent commits 00f1f3d
  • Branches intent_mac

Comments (0)

Files changed (2)

File res/xml/mmac_fragment.xml

             android:key="key_mmac_restore" />
 
         <Preference
+            android:title="Reload MMAC types"
+            android:key="key_types_reload" />
+
+        <Preference
+            android:title="Restore MMAC types"
+            android:key="key_types_restore" />
+
+        <Preference
             android:title="Reload Intent policy"
             android:key="key_intent_reload" />
 

File src/com/android/seandroid_admin/MMACFragment.java

     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 KEY_TYPES_RELOAD = "key_types_reload";
+    private static final String KEY_TYPES_RESTORE = "key_types_restore";
 
     private static final String MMAC_POLICY_FILE = "mac_permissions.xml";
     private static final String INTENT_POLICY_FILE = "intent_mac.xml";
+    private static final String TYPES_POLICY_FILE = "mmac_types.xml";
 
     private CheckBoxPreference mMMACenforceCheckbox;
     private Preference mMMACreload, mMMACrestore;
     private Preference mIntentReload, mIntentRestore;
+    private Preference mTypesReload, mTypesRestore;
 
     private File mMMACpolicyFile = null;
     private File mIntentPolicyFile = null;
+    private File mTypesPolicyFile = null;
 
     private String mMMACenforceCheckboxSummaryChecked;
     private String mMMACenforceCheckboxSummaryUnchecked;
             if (extFileDir != null) {
                 mMMACpolicyFile = new File(extFileDir, MMAC_POLICY_FILE);
                 mIntentPolicyFile = new File(extFileDir, INTENT_POLICY_FILE);
+                mTypesPolicyFile = new File(extFileDir, TYPES_POLICY_FILE);
             }
 
             mMMACenforceCheckbox =
                     return false;
                 }
             });
+
+            mTypesRestore =
+                    getPreferenceScreen().findPreference(KEY_TYPES_RESTORE);
+            mTypesRestore.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                @Override
+                public boolean onPreferenceClick(Preference preference) {
+                    Log.v(TAG, "Delete custom MMAC types requested");
+                    if (!mAdmin.mDPM.setCustomPolicyFile(mAdmin.mDeviceAdmin,
+                            DevicePolicyManager.MMAC_TYPES_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;
+                }
+            });
+
+            mTypesReload =
+                    getPreferenceScreen().findPreference(KEY_TYPES_RELOAD);
+            mTypesReload.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                @Override
+                public boolean onPreferenceClick(Preference preference) {
+                    Log.v(TAG, "Reload of MMAC types requested");
+                    try {
+                        byte[] policy = FileUtils.readFileToByteArray(mTypesPolicyFile);
+                        if (!mAdmin.mDPM.setCustomPolicyFile(mAdmin.mDeviceAdmin,
+                                DevicePolicyManager.MMAC_TYPES_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.setEnabled(true);
+
+            mTypesReload.setEnabled(true);
+            if (mTypesPolicyFile != null) {
+                mTypesReload.setSummary(mTypesPolicyFile.getPath());
+            } else {
+                mTypesReload.setSummary(R.string.ext_storage_unavail);
+            }
+            mTypesRestore.setEnabled(true);
         }
     }