Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 546f75c5 authored by Fred Quintana's avatar Fred Quintana Committed by The Android Open Source Project
Browse files

Merge branch 'readonly-p4-master'

parents 8ecf3b87 26fc5eba
Loading
Loading
Loading
Loading
+333 −223
Original line number Diff line number Diff line
@@ -36,6 +36,9 @@ import android.os.SystemClock;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.app.PendingIntent;
import android.app.NotificationManager;
import android.app.Notification;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -45,6 +48,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;

import com.android.internal.telephony.TelephonyIntents;
import com.android.internal.R;
import com.google.android.collect.Lists;
import com.google.android.collect.Maps;

@@ -165,6 +169,8 @@ public class AccountManagerService extends IAccountManager.Stub {
    }

    public String getPassword(Account account) {
        long identityToken = clearCallingIdentity();
        try {
            SQLiteDatabase db = mOpenHelper.getReadableDatabase();
            Cursor cursor = db.query(TABLE_ACCOUNTS, new String[]{ACCOUNTS_PASSWORD},
                    ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
@@ -177,9 +183,14 @@ public class AccountManagerService extends IAccountManager.Stub {
            } finally {
                cursor.close();
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public String getUserData(Account account, String key) {
        long identityToken = clearCallingIdentity();
        try {
            SQLiteDatabase db = mOpenHelper.getReadableDatabase();
            db.beginTransaction();
            try {
@@ -202,9 +213,14 @@ public class AccountManagerService extends IAccountManager.Stub {
                db.setTransactionSuccessful();
                db.endTransaction();
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public String[] getAuthenticatorTypes() {
        long identityToken = clearCallingIdentity();
        try {
            Collection<AccountAuthenticatorCache.AuthenticatorInfo> authenticatorCollection =
                    mAuthenticatorCache.getAllAuthenticators();
            String[] types = new String[authenticatorCollection.size()];
@@ -214,13 +230,23 @@ public class AccountManagerService extends IAccountManager.Stub {
                i++;
            }
            return types;
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public Account[] getAccounts() {
        long identityToken = clearCallingIdentity();
        try {
            return getAccountsByType(null);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public Account[] getAccountsByType(String accountType) {
        long identityToken = clearCallingIdentity();
        try {
            SQLiteDatabase db = mOpenHelper.getReadableDatabase();

            final String selection = accountType == null ? null : (ACCOUNTS_TYPE + "=?");
@@ -238,10 +264,15 @@ public class AccountManagerService extends IAccountManager.Stub {
            } finally {
                cursor.close();
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public boolean addAccount(Account account, String password, Bundle extras) {
        // fails if the account already exists
        long identityToken = clearCallingIdentity();
        try {
            SQLiteDatabase db = mOpenHelper.getWritableDatabase();
            db.beginTransaction();
            try {
@@ -274,6 +305,9 @@ public class AccountManagerService extends IAccountManager.Stub {
            } finally {
                db.endTransaction();
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    private long insertExtra(SQLiteDatabase db, long accountId, String key, String value) {
@@ -285,6 +319,8 @@ public class AccountManagerService extends IAccountManager.Stub {
    }

    public void removeAccount(Account account) {
        long identityToken = clearCallingIdentity();
        try {
            synchronized (mAuthTokenCache) {
                ArrayList<AuthTokenKey> keysToRemove = Lists.newArrayList();
                for (AuthTokenKey key : mAuthTokenCache.keySet()) {
@@ -301,9 +337,14 @@ public class AccountManagerService extends IAccountManager.Stub {
                        new String[]{account.mName, account.mType});
                mContext.sendBroadcast(ACCOUNTS_CHANGED_INTENT);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void invalidateAuthToken(String accountType, String authToken) {
        long identityToken = clearCallingIdentity();
        try {
            SQLiteDatabase db = mOpenHelper.getWritableDatabase();
            db.beginTransaction();
            try {
@@ -312,6 +353,9 @@ public class AccountManagerService extends IAccountManager.Stub {
            } finally {
                db.endTransaction();
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    private void invalidateAuthToken(SQLiteDatabase db, String accountType, String authToken) {
@@ -390,6 +434,8 @@ public class AccountManagerService extends IAccountManager.Stub {
    }

    public String peekAuthToken(Account account, String authTokenType) {
        long identityToken = clearCallingIdentity();
        try {
            synchronized (mAuthTokenCache) {
                AuthTokenKey key = new AuthTokenKey(account, authTokenType);
                if (mAuthTokenCache.containsKey(key)) {
@@ -397,26 +443,46 @@ public class AccountManagerService extends IAccountManager.Stub {
                }
                return readAuthTokenFromDatabase(account, authTokenType);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void setAuthToken(Account account, String authTokenType, String authToken) {
        long identityToken = clearCallingIdentity();
        try {
            cacheAuthToken(account, authTokenType, authToken);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void setPassword(Account account, String password) {
        long identityToken = clearCallingIdentity();
        try {
            ContentValues values = new ContentValues();
            values.put(ACCOUNTS_PASSWORD, password);
            mOpenHelper.getWritableDatabase().update(TABLE_ACCOUNTS, values,
                    ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
                    new String[]{account.mName, account.mType});
            mContext.sendBroadcast(ACCOUNTS_CHANGED_INTENT);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void clearPassword(Account account) {
        long identityToken = clearCallingIdentity();
        try {
            setPassword(account, null);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void setUserData(Account account, String key, String value) {
        long identityToken = clearCallingIdentity();
        try {
            SQLiteDatabase db = mOpenHelper.getWritableDatabase();
            db.beginTransaction();
            try {
@@ -442,11 +508,16 @@ public class AccountManagerService extends IAccountManager.Stub {
            } finally {
                db.endTransaction();
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void getAuthToken(IAccountManagerResponse response, final Account account,
            final String authTokenType, final boolean notifyOnAuthFailure,
            final boolean expectActivityLaunch, final Bundle loginOptions) {
        long identityToken = clearCallingIdentity();
        try {
            String authToken = getCachedAuthToken(account, authTokenType);
            if (authToken != null) {
                try {
@@ -494,18 +565,24 @@ public class AccountManagerService extends IAccountManager.Stub {

                        Intent intent = result.getParcelable(Constants.INTENT_KEY);
                        if (intent != null && notifyOnAuthFailure) {
                        doNotification(result.getString(Constants.AUTH_FAILED_MESSAGE_KEY), intent);
                            doNotification(result.getString(Constants.AUTH_FAILED_MESSAGE_KEY),
                                    intent);
                        }
                    }
                    super.onResult(result);
                }
            }.bind();
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }


    public void addAcount(final IAccountManagerResponse response,
            final String accountType, final String authTokenType,
            final boolean expectActivityLaunch, final Bundle options) {
        long identityToken = clearCallingIdentity();
        try {
            new Session(response, accountType, expectActivityLaunch) {
                public void run() throws RemoteException {
                    mAuthenticator.addAccount(this, mAccountType, authTokenType, options);
@@ -516,10 +593,15 @@ public class AccountManagerService extends IAccountManager.Stub {
                            + ", accountType " + accountType;
                }
            }.bind();
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void confirmCredentials(IAccountManagerResponse response,
            final Account account, final boolean expectActivityLaunch) {
        long identityToken = clearCallingIdentity();
        try {
            new Session(response, account.mType, expectActivityLaunch) {
                public void run() throws RemoteException {
                    mAuthenticator.confirmCredentials(this, account);
@@ -529,10 +611,15 @@ public class AccountManagerService extends IAccountManager.Stub {
                            + ", " + account;
                }
            }.bind();
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void confirmPassword(IAccountManagerResponse response, final Account account,
            final String password) {
        long identityToken = clearCallingIdentity();
        try {
            new Session(response, account.mType, false /* expectActivityLaunch */) {
                public void run() throws RemoteException {
                    mAuthenticator.confirmPassword(this, account, password);
@@ -542,11 +629,16 @@ public class AccountManagerService extends IAccountManager.Stub {
                            + ", " + account;
                }
            }.bind();
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void updateCredentials(IAccountManagerResponse response, final Account account,
            final String authTokenType, final boolean expectActivityLaunch,
            final Bundle loginOptions) {
        long identityToken = clearCallingIdentity();
        try {
            new Session(response, account.mType, expectActivityLaunch) {
                public void run() throws RemoteException {
                    mAuthenticator.updateCredentials(this, account, authTokenType, loginOptions);
@@ -559,10 +651,15 @@ public class AccountManagerService extends IAccountManager.Stub {
                            + ", loginOptions " + loginOptions;
                }
            }.bind();
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    public void editProperties(IAccountManagerResponse response, final String accountType,
            final boolean expectActivityLaunch) {
        long identityToken = clearCallingIdentity();
        try {
            new Session(response, accountType, expectActivityLaunch) {
                public void run() throws RemoteException {
                    mAuthenticator.editProperties(this, mAccountType);
@@ -572,6 +669,9 @@ public class AccountManagerService extends IAccountManager.Stub {
                            + ", accountType " + accountType;
                }
            }.bind();
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    private boolean cacheAuthToken(Account account, String authTokenType, String authToken) {
@@ -1000,20 +1100,30 @@ public class AccountManagerService extends IAccountManager.Stub {
    }

    private void doNotification(CharSequence message, Intent intent) {
        long identityToken = clearCallingIdentity();
        try {
            if (Log.isLoggable(TAG, Log.VERBOSE)) {
                Log.v(TAG, "doNotification: " + message + " intent:" + intent);
            }

        // TODO(fredq) add this back in when we fix permissions
//       Notification n = new Notification(android.R.drawable.stat_sys_warning, null, 0 /* when */);
//        n.setLatestEventInfo(mContext, mContext.getText(R.string.notification_title), message,
//            PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
//        ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
//                .notify(NOTIFICATION_ID, n);
            Notification n = new Notification(android.R.drawable.stat_sys_warning, null,
                    0 /* when */);
            n.setLatestEventInfo(mContext, mContext.getText(R.string.notification_title), message,
                PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));
            ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
                    .notify(NOTIFICATION_ID, n);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }

    private void cancelNotification() {
//        ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
//            .cancel(NOTIFICATION_ID);
        long identityToken = clearCallingIdentity();
        try {
            ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE))
                .cancel(NOTIFICATION_ID);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    }
}