]> hydra-www.ietfng.org Git - android-vcpass-oisafe/commitdiff
OI Safe: Fix issue 170. Include a new dialog AllowExternalAccessDialog that is prompt...
authorpeli0101 <peli0101@72b678ce-9140-0410-bee8-679b907dd61a>
Sat, 17 Jan 2009 16:38:06 +0000 (16:38 +0000)
committerpeli0101 <peli0101@72b678ce-9140-0410-bee8-679b907dd61a>
Sat, 17 Jan 2009 16:38:06 +0000 (16:38 +0000)
git-svn-id: http://openintents.googlecode.com/svn/trunk/Safe@1753 72b678ce-9140-0410-bee8-679b907dd61a

AndroidManifest.xml
res/layout/dialog_allow_access.xml [new file with mode: 0644]
res/values/strings.xml
src/org/openintents/safe/FrontDoor.java
src/org/openintents/safe/Preferences.java
src/org/openintents/safe/dialog/AllowExternalAccessDialog.java [new file with mode: 0644]
src/org/openintents/safe/dialog/DialogHostingActivity.java

index 329b9d86aee50eb974e69b5e29a420f7e987286e..28e173a0874c8e2c9b0051be076f8a8f75278542 100644 (file)
@@ -26,7 +26,8 @@
         <meta-data android:name="org.openintents.metadata.EMAIL"\r
                        android:value="@string/about_email" />\r
                        
-        <activity class=".FrontDoor" android:name="FrontDoor" android:label="@string/app_name">
+        <activity class=".FrontDoor" android:name="FrontDoor" android:label="@string/app_name"\r
+                       android:theme="@android:style/Theme.Translucent.NoTitleBar">
                <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />\r
@@ -61,7 +62,9 @@
         <activity class=".ChangePass" android:name="ChangePass" android:label="@string/app_name" />
         <activity class=".Restore" android:name="Restore" android:label="@string/app_name" />
         <activity class=".Preferences" android:name="Preferences" android:label="@string/app_name" />
-        <activity class=".LogOffActivity" android:name="LogOffActivity" android:label="@string/app_name" />
+        <activity class=".LogOffActivity" android:name="LogOffActivity" android:label="@string/app_name" />\r
+        <activity android:name=".dialog.DialogHostingActivity" android:label="@string/app_name"\r
+                       android:theme="@android:style/Theme.Translucent.NoTitleBar" />
         \r
         <activity android:name="org.openintents.distribution.EulaActivity" android:label="@string/eula_title" />\r
         
diff --git a/res/layout/dialog_allow_access.xml b/res/layout/dialog_allow_access.xml
new file mode 100644 (file)
index 0000000..725b4a6
--- /dev/null
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2006-2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+-->\r
+\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+    android:orientation="vertical"\r
+    android:layout_width="fill_parent"\r
+    android:layout_height="wrap_content"\r
+    android:layout_marginBottom="10dip"\r
+           >\r
+       <CheckBox xmlns:android="http://schemas.android.com/apk/res/android"\r
+               android:id="@+id/checkbox"\r
+           android:layout_width="fill_parent"\r
+           android:layout_height="wrap_content"\r
+           android:text="@string/dialog_summary_external_access"\r
+           />\r
+       \r
+    <TextView android:id="@+id/text"\r
+           android:layout_width="fill_parent" \r
+           android:layout_height="wrap_content" \r
+           android:text="@string/dialog_comment_external_access"\r
+           android:layout_margin="10dip" />\r
+</LinearLayout>
\ No newline at end of file
index d0aad5f579ca77820f058552d87fe694e8c3b0cc..8a06cb5e877163da008219231975e524d819e39a 100644 (file)
        <string name="preferences">Preferences</string>\r
        <string name="pref_title_external_access">Allow external access</string>\r
        <string name="pref_summary_external_access">Allow other applications to access safe.</string>\r
+       <string name="dialog_title_external_access">External application tries to access OI Safe</string>\r
+       <string name="dialog_summary_external_access">Allow other applications to access OI Safe.</string>\r
+       <string name="dialog_comment_external_access">This can also be set in Menu / Preferences.</string>\r
        <string name="pref_title_lock_timeout">Lock timeout</string>\r
        <string name="pref_summary_lock_timeout">Minutes before timeout occurs and safe is locked.</string>\r
        <string name="pref_dialog_title_lock_timeout">Lock timeout</string>\r
index ff3adab68dd784d1c64957d15cdb1bd670099124..4d7ce4d7bf9186fbf46340d72ce39e93724f349c 100644 (file)
@@ -20,6 +20,7 @@ package org.openintents.safe;
 import java.util.ArrayList;\r
 \r
 import org.openintents.intents.CryptoIntents;\r
+import org.openintents.safe.dialog.DialogHostingActivity;\r
 import org.openintents.safe.service.ServiceDispatch;\r
 import org.openintents.safe.service.ServiceDispatchImpl;\r
 \r
@@ -51,7 +52,7 @@ public class FrontDoor extends Activity {
        private static String TAG = "FrontDoor";\r
        \r
        private static final int REQUEST_CODE_ASK_PASSWORD = 1;\r
-       private static final int REQUEST_CODE_GRANT_EXTERNAL_ACCESS = 2;\r
+       private static final int REQUEST_CODE_ALLOW_EXTERNAL_ACCESS = 2;\r
        \r
 \r
        private DBHelper dbHelper;\r
@@ -93,10 +94,20 @@ public class FrontDoor extends Activity {
                                        // TODO Auto-generated catch block\r
                                        e1.printStackTrace();\r
                                }\r
-                               actionDispatch();\r
+\r
+                       boolean externalAccess = mPreferences.getBoolean(Preferences.PREFERENCE_ALLOW_EXTERNAL_ACCESS, false);\r
+                       boolean isLocal = isIntentLocal();\r
+                       \r
+                       if (isLocal || externalAccess) {\r
+                               actionDispatch();\r
+                       } else {\r
+                               // ask first\r
+                               showDialogAllowExternalAccess();\r
+                       }\r
                                break;\r
-                       case REQUEST_CODE_GRANT_EXTERNAL_ACCESS:\r
-                               \r
+                       case REQUEST_CODE_ALLOW_EXTERNAL_ACCESS:\r
+\r
+                       actionDispatch();\r
                                break;\r
                        }\r
                        \r
@@ -105,6 +116,15 @@ public class FrontDoor extends Activity {
                        finish();\r
                }\r
        }\r
+\r
+       /**\r
+        * \r
+        */\r
+       private void showDialogAllowExternalAccess() {\r
+               Intent i = new Intent(this, DialogHostingActivity.class);\r
+               i.putExtra(DialogHostingActivity.EXTRA_DIALOG_ID, DialogHostingActivity.DIALOG_ID_ALLOW_EXTERNAL_ACCESS);\r
+               this.startActivityForResult(i, REQUEST_CODE_ALLOW_EXTERNAL_ACCESS);\r
+       }\r
        \r
        protected void actionDispatch () {    \r
                final Intent thisIntent = getIntent();\r
@@ -118,7 +138,7 @@ public class FrontDoor extends Activity {
                ch.setPassword(masterKey);\r
         }\r
 \r
-        boolean externalAccess = mPreferences.getBoolean("external_access", false);\r
+        boolean externalAccess = mPreferences.getBoolean(Preferences.PREFERENCE_ALLOW_EXTERNAL_ACCESS, false);\r
 \r
         if (action == null || action.equals(Intent.ACTION_MAIN)){\r
                //TODO: When launched from debugger, action is null. Other such cases?\r
@@ -356,8 +376,7 @@ public class FrontDoor extends Activity {
        //--------------------------- service stuff ------------\r
        private void initService() {\r
 \r
-        String action = getIntent().getAction();\r
-        boolean isLocal = action == null || action.equals(Intent.ACTION_MAIN);\r
+        boolean isLocal = isIntentLocal();\r
                conn = new ServiceDispatchConnection(isLocal);\r
                Intent i = new Intent();\r
                i.setClass(this, ServiceDispatchImpl.class);\r
@@ -365,6 +384,15 @@ public class FrontDoor extends Activity {
                bindService( i, conn, Context.BIND_AUTO_CREATE);\r
        }\r
 \r
+       /**\r
+        * @return\r
+        */\r
+       private boolean isIntentLocal() {\r
+               String action = getIntent().getAction();\r
+        boolean isLocal = action == null || action.equals(Intent.ACTION_MAIN);\r
+               return isLocal;\r
+       }\r
+\r
        private void releaseService() {\r
                if (conn != null ) {\r
                        unbindService( conn );\r
@@ -410,8 +438,15 @@ public class FrontDoor extends Activity {
                                } else {\r
                                        if (debug) Log.d(TAG, "service already started");\r
                                        //service already started, so don't need to ask pw.\r
-                                       masterKey = service.getPassword();\r
-                                       actionDispatch();\r
+\r
+                               boolean externalAccess = mPreferences.getBoolean(Preferences.PREFERENCE_ALLOW_EXTERNAL_ACCESS, false);\r
+                               \r
+                               if (askPassIsLocal || externalAccess) {\r
+                                               masterKey = service.getPassword();\r
+                                               actionDispatch();\r
+                               } else {\r
+                                       showDialogAllowExternalAccess();\r
+                               }\r
                                }\r
                        } catch (RemoteException e) {\r
                                Log.d(TAG, e.toString());\r
index 50470287c71de0d95a8fc6b8af3e420ef6e85aca..6161c64d9cef89c061d9ad5d21d1cfca348c1b36 100644 (file)
@@ -5,6 +5,8 @@ import android.preference.PreferenceActivity;
 
 public class Preferences extends PreferenceActivity {
 
+       public static final String PREFERENCE_ALLOW_EXTERNAL_ACCESS = "external_access";
+       
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
diff --git a/src/org/openintents/safe/dialog/AllowExternalAccessDialog.java b/src/org/openintents/safe/dialog/AllowExternalAccessDialog.java
new file mode 100644 (file)
index 0000000..f46ae0c
--- /dev/null
@@ -0,0 +1,80 @@
+package org.openintents.safe.dialog;\r
+\r
+import org.openintents.safe.Preferences;\r
+import org.openintents.safe.R;\r
+\r
+import android.app.AlertDialog;\r
+import android.content.Context;\r
+import android.content.DialogInterface;\r
+import android.content.SharedPreferences;\r
+import android.content.DialogInterface.OnClickListener;\r
+import android.os.Bundle;\r
+import android.preference.PreferenceManager;\r
+import android.view.LayoutInflater;\r
+import android.view.View;\r
+import android.widget.CheckBox;\r
+\r
+public class AllowExternalAccessDialog extends AlertDialog implements OnClickListener {\r
+       private static final String TAG = "FilenameDialog";\r
+\r
+    private static final String BUNDLE_TAGS = "tags";\r
+    \r
+       protected static final int DIALOG_ID_NO_FILE_MANAGER_AVAILABLE = 2;\r
+    \r
+    Context mContext;\r
+    \r
+    CheckBox mCheckBox;\r
+    \r
+    public AllowExternalAccessDialog(Context context) {\r
+        super(context);\r
+        mContext = context;\r
+        \r
+        setTitle(context.getText(R.string.dialog_title_external_access));\r
+        setButton(context.getText(android.R.string.ok), this);\r
+        setButton2(context.getText(android.R.string.cancel), (OnClickListener) null);\r
+        setIcon(android.R.drawable.ic_dialog_alert);\r
+        \r
+        LayoutInflater inflater = \r
+                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r
+        View view = inflater.inflate(R.layout.dialog_allow_access, null);\r
+        setView(view);\r
+\r
+        \r
+        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);\r
+        boolean externalAccess = sp.getBoolean(Preferences.PREFERENCE_ALLOW_EXTERNAL_ACCESS, false);\r
+        \r
+        mCheckBox = (CheckBox) view.findViewById(R.id.checkbox);\r
+        // mCheckBox.setText(R.string.pref_summary_external_access);\r
+        mCheckBox.setChecked(externalAccess);\r
+\r
+    }\r
+    \r
+          \r
+       public void onClick(DialogInterface dialog, int which) {\r
+       if (which == BUTTON1) {\r
+               // User pressed OK\r
+               boolean externalAccess = mCheckBox.isChecked();\r
+\r
+            SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);\r
+            SharedPreferences.Editor editor = sp.edit();\r
+            editor.putBoolean(Preferences.PREFERENCE_ALLOW_EXTERNAL_ACCESS, externalAccess);\r
+            editor.commit();\r
+            \r
+       }\r
+               \r
+       }\r
+    \r
+\r
+       @Override\r
+    public Bundle onSaveInstanceState() {\r
+        Bundle state = super.onSaveInstanceState();\r
+        state.putString(BUNDLE_TAGS, "");\r
+        return state;\r
+    }\r
+    \r
+    @Override\r
+    public void onRestoreInstanceState(Bundle savedInstanceState) {\r
+        super.onRestoreInstanceState(savedInstanceState);\r
+        String tags = savedInstanceState.getString(BUNDLE_TAGS);\r
+    }\r
+}\r
index 04c84623dd29ab47acb0be1bfdde9fe908a97685..ff42d42a2f4448d10d8254ffbc4c3241c37401d5 100644 (file)
@@ -3,7 +3,6 @@ package org.openintents.safe.dialog;
 import org.openintents.distribution.GetFromMarketDialog;\r
 import org.openintents.distribution.RD;\r
 import org.openintents.intents.FileManagerIntents;\r
-import org.openintents.safe.R;\r
 import org.openintents.util.IntentUtils;\r
 \r
 import android.app.Activity;\r
@@ -22,6 +21,7 @@ public class DialogHostingActivity extends Activity {
        public static final int DIALOG_ID_SAVE = 1;\r
        public static final int DIALOG_ID_OPEN = 2;\r
        public static final int DIALOG_ID_NO_FILE_MANAGER_AVAILABLE = 3;\r
+       public static final int DIALOG_ID_ALLOW_EXTERNAL_ACCESS = 4;\r
        \r
        public static final String EXTRA_DIALOG_ID = "org.openintents.notepad.extra.dialog_id";\r
        \r
@@ -46,6 +46,9 @@ public class DialogHostingActivity extends Activity {
                        case DIALOG_ID_NO_FILE_MANAGER_AVAILABLE:\r
                                Log.i(TAG, "Show no file manager dialog");\r
                                showDialog(DIALOG_ID_NO_FILE_MANAGER_AVAILABLE);\r
+                       case DIALOG_ID_ALLOW_EXTERNAL_ACCESS:\r
+                               Log.i(TAG, "Show allow access dialog");\r
+                               showDialog(DIALOG_ID_ALLOW_EXTERNAL_ACCESS);\r
                                break;\r
                        }\r
                }\r
@@ -110,7 +113,8 @@ public class DialogHostingActivity extends Activity {
                                        RD.string.filemanager_not_available,\r
                                        RD.string.filemanager_get_oi_filemanager,\r
                                        RD.string.filemanager_market_uri);\r
-\r
+               case DIALOG_ID_ALLOW_EXTERNAL_ACCESS:\r
+                       return new AllowExternalAccessDialog(this);\r
                }\r
                return null;\r
        }\r