瀏覽代碼

Added helper app to work around the issue of lost credentials at boot time affecting ownCloud apps installed from the Google Play Store in Android 4.1.x

David A. Velasco 12 年之前
父節點
當前提交
0ad4898ccf

+ 8 - 0
oc_jb_workaround/.classpath

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry kind="output" path="bin/classes"/>
+</classpath>

+ 19 - 0
oc_jb_workaround/.gitignore

@@ -0,0 +1,19 @@
+# built application files
+*.apk
+*.ap_
+
+# files for the dex VM
+*.dex
+
+# Java class files
+*.class
+
+# generated files
+bin/
+gen/
+
+# Local configuration file (sdk path, etc)
+local.properties
+
+# Mac .DS_Store files
+.DS_Store

+ 33 - 0
oc_jb_workaround/.project

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>owncloud-android-workaround-accounts</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 4 - 0
oc_jb_workaround/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.source=1.6

+ 28 - 0
oc_jb_workaround/AndroidManifest.xml

@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.owncloud.android.workaround.accounts"
+    android:versionCode="0100000"
+    android:versionName="1.0" >
+
+    <uses-sdk
+        android:minSdkVersion="16"
+        android:targetSdkVersion="16" />
+
+    <application
+        android:allowBackup="false"
+        android:icon="@drawable/oc_workaround_icon"
+        android:label="@string/app_name"
+        android:theme="@style/AppTheme" >
+        <service
+            android:name=".AccountAuthenticatorService"
+            android:exported="false">
+            <intent-filter android:priority="1">
+                <action android:name="android.accounts.AccountAuthenticator" />
+            </intent-filter>
+            <meta-data
+                android:name="android.accounts.AccountAuthenticator"
+                android:resource="@xml/authenticator" />
+        </service>
+    </application>
+
+</manifest>

+ 10 - 0
oc_jb_workaround/README.md

@@ -0,0 +1,10 @@
+ownCloud Jelly Bean Workaround
+==============================
+
+Helper app to work around the problem of lost credentials at reboot time found
+in devices with Android 4.1.x. 
+
+Only needed for ownCloud apps installed from the Google Play Store.
+
+See more information about the bug here: 
+http://code.google.com/p/android/issues/detail?id=34880

+ 20 - 0
oc_jb_workaround/proguard-project.txt

@@ -0,0 +1,20 @@
+# To enable ProGuard in your project, edit project.properties
+# to define the proguard.config property as described in that file.
+#
+# Add project specific ProGuard rules here.
+# By default, the flags in this file are appended to flags specified
+# in ${sdk.dir}/tools/proguard/proguard-android.txt
+# You can edit the include path and order by changing the ProGuard
+# include property in project.properties.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# Add any project specific keep options here:
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}

+ 14 - 0
oc_jb_workaround/project.properties

@@ -0,0 +1,14 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system edit
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+#
+# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
+#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
+
+# Project target.
+target=android-16

二進制
oc_jb_workaround/res/drawable-hdpi/oc_icon.png


二進制
oc_jb_workaround/res/drawable-hdpi/oc_workaround_icon.png


二進制
oc_jb_workaround/res/drawable-ldpi/oc_icon.png


二進制
oc_jb_workaround/res/drawable-ldpi/oc_workaround_icon.png


二進制
oc_jb_workaround/res/drawable-mdpi/oc_icon.png


二進制
oc_jb_workaround/res/drawable-mdpi/oc_workaround_icon.png


二進制
oc_jb_workaround/res/drawable-xhdpi/oc_icon.png


二進制
oc_jb_workaround/res/drawable-xhdpi/oc_workaround_icon.png


+ 11 - 0
oc_jb_workaround/res/values-v11/styles.xml

@@ -0,0 +1,11 @@
+<resources>
+
+    <!--
+        Base application theme for API 11+. This theme completely replaces
+        AppBaseTheme from res/values/styles.xml on API 11+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
+        <!-- API 11 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 12 - 0
oc_jb_workaround/res/values-v14/styles.xml

@@ -0,0 +1,12 @@
+<resources>
+
+    <!--
+        Base application theme for API 14+. This theme completely replaces
+        AppBaseTheme from BOTH res/values/styles.xml and
+        res/values-v11/styles.xml on API 14+ devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
+        <!-- API 14 theme customizations can go here. -->
+    </style>
+
+</resources>

+ 6 - 0
oc_jb_workaround/res/values/strings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <string name="app_name">ownCloud Jelly Bean Workaround for lost credentials</string>
+
+</resources>

+ 20 - 0
oc_jb_workaround/res/values/styles.xml

@@ -0,0 +1,20 @@
+<resources>
+
+    <!--
+        Base application theme, dependent on API level. This theme is replaced
+        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
+    -->
+    <style name="AppBaseTheme" parent="android:Theme.Light">
+        <!--
+            Theme customizations available in newer API levels can go in
+            res/values-vXX/styles.xml, while customizations related to
+            backward-compatibility can go here.
+        -->
+    </style>
+
+    <!-- Application theme. -->
+    <style name="AppTheme" parent="AppBaseTheme">
+        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
+    </style>
+
+</resources>

+ 7 - 0
oc_jb_workaround/res/xml/authenticator.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
+                       android:accountType="owncloud"
+                       android:icon="@drawable/oc_icon"
+                       android:label="@string/app_name"
+                       android:smallIcon="@drawable/oc_icon">  
+</account-authenticator>

+ 103 - 0
oc_jb_workaround/src/com/owncloud/android/workaround/accounts/AccountAuthenticatorService.java

@@ -0,0 +1,103 @@
+/* ownCloud Jelly Bean Workaround for lost credentials
+ *
+ *   Copyright (C) 2013 ownCloud Inc.
+ */
+
+package com.owncloud.android.workaround.accounts;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.AccountManager;
+import android.accounts.NetworkErrorException;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.IBinder;
+
+public class AccountAuthenticatorService extends Service {
+
+    private AccountAuthenticator mAuthenticator;
+    static final public String ACCOUNT_TYPE = "owncloud";
+
+    @Override
+    public void onCreate() {
+        super.onCreate();
+        mAuthenticator = new AccountAuthenticator(this);
+    }
+
+    @Override
+    public IBinder onBind(Intent intent) {
+        return mAuthenticator.getIBinder();
+    }
+    
+    
+    public static class AccountAuthenticator extends AbstractAccountAuthenticator {
+
+    	public AccountAuthenticator(Context context) {
+            super(context);
+        }
+
+        @Override
+        public Bundle addAccount(AccountAuthenticatorResponse response,
+                String accountType, String authTokenType,
+                String[] requiredFeatures, Bundle options)
+                throws NetworkErrorException {
+            return getCommonResultBundle();
+        }
+
+        
+		@Override
+        public Bundle confirmCredentials(AccountAuthenticatorResponse response,
+                Account account, Bundle options) throws NetworkErrorException {
+            return getCommonResultBundle();
+        }
+
+        @Override
+        public Bundle editProperties(AccountAuthenticatorResponse response,
+                String accountType) {
+            return getCommonResultBundle();
+        }
+
+        @Override
+        public Bundle getAuthToken(AccountAuthenticatorResponse response,
+                Account account, String authTokenType, Bundle options)
+                throws NetworkErrorException {
+            return getCommonResultBundle();
+        }
+
+        @Override
+        public String getAuthTokenLabel(String authTokenType) {
+            return "";
+        }
+
+        @Override
+        public Bundle hasFeatures(AccountAuthenticatorResponse response,
+                Account account, String[] features) throws NetworkErrorException {
+            return getCommonResultBundle();
+        }
+
+        @Override
+        public Bundle updateCredentials(AccountAuthenticatorResponse response,
+                Account account, String authTokenType, Bundle options)
+                throws NetworkErrorException {
+            return getCommonResultBundle();
+        }
+
+        @Override
+        public Bundle getAccountRemovalAllowed(
+                AccountAuthenticatorResponse response, Account account)
+                throws NetworkErrorException {
+            return getCommonResultBundle();
+        }
+
+        private Bundle getCommonResultBundle() {
+        	Bundle resultBundle = new Bundle();
+            resultBundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
+            resultBundle.putString(AccountManager.KEY_ERROR_MESSAGE, "This is just a workaround, not a real account authenticator");
+            return resultBundle;
+		}
+
+    }
+}