Search in sources :

Example 1 with Pair

use of android.util.Pair in project android_frameworks_base by ParanoidAndroid.

the class DatabaseGeneralTest method testDefaultDatabaseErrorHandler.

@LargeTest
public void testDefaultDatabaseErrorHandler() {
    DefaultDatabaseErrorHandler errorHandler = new DefaultDatabaseErrorHandler();
    // close the database. and call corruption handler.
    // it should delete the database file.
    File dbfile = new File(mDatabase.getPath());
    mDatabase.close();
    assertFalse(mDatabase.isOpen());
    assertTrue(dbfile.exists());
    try {
        errorHandler.onCorruption(mDatabase);
        assertFalse(dbfile.exists());
    } catch (Exception e) {
        fail("unexpected");
    }
    // create an in-memory database. and corruption handler shouldn't try to delete it
    SQLiteDatabase memoryDb = SQLiteDatabase.openOrCreateDatabase(":memory:", null);
    assertNotNull(memoryDb);
    memoryDb.close();
    assertFalse(memoryDb.isOpen());
    try {
        errorHandler.onCorruption(memoryDb);
    } catch (Exception e) {
        fail("unexpected");
    }
    // create a database, keep it open, call corruption handler. database file should be deleted
    SQLiteDatabase dbObj = SQLiteDatabase.openOrCreateDatabase(mDatabase.getPath(), null);
    assertTrue(dbfile.exists());
    assertNotNull(dbObj);
    assertTrue(dbObj.isOpen());
    try {
        errorHandler.onCorruption(dbObj);
        assertFalse(dbfile.exists());
    } catch (Exception e) {
        fail("unexpected");
    }
    // create a database, attach 2 more databases to it
    //    attached database # 1: ":memory:"
    //    attached database # 2: mDatabase.getPath() + "1";
    // call corruption handler. database files including the one for attached database # 2
    // should be deleted
    String attachedDb1File = mDatabase.getPath() + "1";
    dbObj = SQLiteDatabase.openOrCreateDatabase(mDatabase.getPath(), null);
    dbObj.execSQL("ATTACH DATABASE ':memory:' as memoryDb");
    dbObj.execSQL("ATTACH DATABASE '" + attachedDb1File + "' as attachedDb1");
    assertTrue(dbfile.exists());
    assertTrue(new File(attachedDb1File).exists());
    assertNotNull(dbObj);
    assertTrue(dbObj.isOpen());
    List<Pair<String, String>> attachedDbs = dbObj.getAttachedDbs();
    try {
        errorHandler.onCorruption(dbObj);
        assertFalse(dbfile.exists());
        assertFalse(new File(attachedDb1File).exists());
    } catch (Exception e) {
        fail("unexpected");
    }
    // same as above, except this is a bit of stress testing. attach 5 database files
    // and make sure they are all removed.
    int N = 5;
    ArrayList<String> attachedDbFiles = new ArrayList<String>(N);
    for (int i = 0; i < N; i++) {
        attachedDbFiles.add(mDatabase.getPath() + i);
    }
    dbObj = SQLiteDatabase.openOrCreateDatabase(mDatabase.getPath(), null);
    dbObj.execSQL("ATTACH DATABASE ':memory:' as memoryDb");
    for (int i = 0; i < N; i++) {
        dbObj.execSQL("ATTACH DATABASE '" + attachedDbFiles.get(i) + "' as attachedDb" + i);
    }
    assertTrue(dbfile.exists());
    for (int i = 0; i < N; i++) {
        assertTrue(new File(attachedDbFiles.get(i)).exists());
    }
    assertNotNull(dbObj);
    assertTrue(dbObj.isOpen());
    attachedDbs = dbObj.getAttachedDbs();
    try {
        errorHandler.onCorruption(dbObj);
        assertFalse(dbfile.exists());
        for (int i = 0; i < N; i++) {
            assertFalse(new File(attachedDbFiles.get(i)).exists());
        }
    } catch (Exception e) {
        fail("unexpected");
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ArrayList(java.util.ArrayList) File(java.io.File) SQLiteException(android.database.sqlite.SQLiteException) Pair(android.util.Pair) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 2 with Pair

use of android.util.Pair in project android_frameworks_base by ParanoidAndroid.

the class MediaArtistNativeHelper method findVideoResolution.

/**
     * Calculates video resolution for output clip
     * based on clip's height and aspect ratio of storyboard
     *
     * @param aspectRatio The aspect ratio of story board
     * @param height The height of clip
     *
     * @return The video resolution
     */
private int findVideoResolution(int aspectRatio, int height) {
    final Pair<Integer, Integer>[] resolutions;
    final Pair<Integer, Integer> maxResolution;
    int retValue = VideoFrameSize.SIZE_UNDEFINED;
    switch(aspectRatio) {
        case MediaProperties.ASPECT_RATIO_3_2:
            if (height == MediaProperties.HEIGHT_480)
                retValue = VideoFrameSize.NTSC;
            else if (height == MediaProperties.HEIGHT_720)
                retValue = VideoFrameSize.W720p;
            break;
        case MediaProperties.ASPECT_RATIO_16_9:
            if (height == MediaProperties.HEIGHT_480)
                retValue = VideoFrameSize.WVGA16x9;
            else if (height == MediaProperties.HEIGHT_720)
                retValue = VideoFrameSize.V720p;
            else if (height == MediaProperties.HEIGHT_1080)
                retValue = VideoFrameSize.V1080p;
            break;
        case MediaProperties.ASPECT_RATIO_4_3:
            if (height == MediaProperties.HEIGHT_480)
                retValue = VideoFrameSize.VGA;
            else if (height == MediaProperties.HEIGHT_720)
                retValue = VideoFrameSize.S720p;
            break;
        case MediaProperties.ASPECT_RATIO_5_3:
            if (height == MediaProperties.HEIGHT_480)
                retValue = VideoFrameSize.WVGA;
            break;
        case MediaProperties.ASPECT_RATIO_11_9:
            if (height == MediaProperties.HEIGHT_144)
                retValue = VideoFrameSize.QCIF;
            else if (height == MediaProperties.HEIGHT_288)
                retValue = VideoFrameSize.CIF;
            break;
    }
    if (retValue == VideoFrameSize.SIZE_UNDEFINED) {
        resolutions = MediaProperties.getSupportedResolutions(mVideoEditor.getAspectRatio());
        // Get the highest resolution
        maxResolution = resolutions[resolutions.length - 1];
        retValue = findVideoResolution(mVideoEditor.getAspectRatio(), maxResolution.second);
    }
    return retValue;
}
Also used : Paint(android.graphics.Paint) Pair(android.util.Pair)

Example 3 with Pair

use of android.util.Pair in project android_frameworks_base by ParanoidAndroid.

the class UserTile method queryForUserInformation.

private void queryForUserInformation() {
    Context currentUserContext = null;
    UserInfo userInfo = null;
    try {
        userInfo = ActivityManagerNative.getDefault().getCurrentUser();
        currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Couldn't create user context", e);
        throw new RuntimeException(e);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't get user info", e);
    }
    final int userId = userInfo.id;
    final String userName = userInfo.name;
    final Context context = currentUserContext;
    mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {

        @Override
        protected Pair<String, Drawable> doInBackground(Void... params) {
            try {
                // The system needs some time to change the picture, if we try to load it when we receive the broadcast, we will load the old one
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            final UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
            // Fall back to the UserManager nickname if we can't read the name from the local
            // profile below.
            String name = userName;
            Drawable avatar = null;
            Bitmap rawAvatar = um.getUserIcon(userId);
            if (rawAvatar != null) {
                avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
            } else {
                avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
            }
            // usually valid
            if (um.getUsers().size() <= 1) {
                // Try and read the display name from the local profile
                final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
                        }
                    } finally {
                        cursor.close();
                    }
                }
            }
            return new Pair<String, Drawable>(name, avatar);
        }

        @Override
        protected void onPostExecute(Pair<String, Drawable> result) {
            super.onPostExecute(result);
            setUserTileInfo(result.first, result.second);
            mUserInfoTask = null;
        }
    };
    mUserInfoTask.execute();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) UserInfo(android.content.pm.UserInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Example 4 with Pair

use of android.util.Pair in project android_frameworks_base by ParanoidAndroid.

the class PhoneStatusBar method recreateStatusBar.

private void recreateStatusBar() {
    mRecreating = true;
    mStatusBarContainer.removeAllViews();
    // extract icons from the soon-to-be recreated viewgroup.
    int nIcons = mStatusIcons.getChildCount();
    ArrayList<StatusBarIcon> icons = new ArrayList<StatusBarIcon>(nIcons);
    ArrayList<String> iconSlots = new ArrayList<String>(nIcons);
    for (int i = 0; i < nIcons; i++) {
        StatusBarIconView iconView = (StatusBarIconView) mStatusIcons.getChildAt(i);
        icons.add(iconView.getStatusBarIcon());
        iconSlots.add(iconView.getStatusBarSlot());
    }
    // extract notifications.
    int nNotifs = mNotificationData.size();
    ArrayList<Pair<IBinder, StatusBarNotification>> notifications = new ArrayList<Pair<IBinder, StatusBarNotification>>(nNotifs);
    copyNotifications(notifications, mNotificationData);
    mNotificationData.clear();
    makeStatusBarView();
    repositionNavigationBar();
    mNavigationBarView.updateResources();
    // recreate StatusBarIconViews.
    for (int i = 0; i < nIcons; i++) {
        StatusBarIcon icon = icons.get(i);
        String slot = iconSlots.get(i);
        addIcon(slot, i, i, icon);
    }
    // recreate notifications.
    for (int i = 0; i < nNotifs; i++) {
        Pair<IBinder, StatusBarNotification> notifData = notifications.get(i);
        addNotificationViews(notifData.first, notifData.second);
    }
    setAreThereNotifications();
    mStatusBarContainer.addView(mStatusBarWindow);
    updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
    mRecreating = false;
}
Also used : IBinder(android.os.IBinder) StatusBarNotification(android.service.notification.StatusBarNotification) ArrayList(java.util.ArrayList) StatusBarIcon(com.android.internal.statusbar.StatusBarIcon) Point(android.graphics.Point) StatusBarIconView(com.android.systemui.statusbar.StatusBarIconView) Pair(android.util.Pair)

Example 5 with Pair

use of android.util.Pair in project android_frameworks_base by ParanoidAndroid.

the class QuickSettings method queryForUserInformation.

private void queryForUserInformation() {
    Context currentUserContext = null;
    UserInfo userInfo = null;
    try {
        userInfo = ActivityManagerNative.getDefault().getCurrentUser();
        currentUserContext = mContext.createPackageContextAsUser("android", 0, new UserHandle(userInfo.id));
    } catch (NameNotFoundException e) {
        Log.e(TAG, "Couldn't create user context", e);
        throw new RuntimeException(e);
    } catch (RemoteException e) {
        Log.e(TAG, "Couldn't get user info", e);
    }
    final int userId = userInfo.id;
    final String userName = userInfo.name;
    final Context context = currentUserContext;
    mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {

        @Override
        protected Pair<String, Drawable> doInBackground(Void... params) {
            final UserManager um = UserManager.get(mContext);
            // Fall back to the UserManager nickname if we can't read the name from the local
            // profile below.
            String name = userName;
            Drawable avatar = null;
            Bitmap rawAvatar = um.getUserIcon(userId);
            if (rawAvatar != null) {
                avatar = new BitmapDrawable(mContext.getResources(), rawAvatar);
            } else {
                avatar = mContext.getResources().getDrawable(R.drawable.ic_qs_default_user);
                mUseDefaultAvatar = true;
            }
            // usually valid
            if (um.getUsers().size() <= 1) {
                // Try and read the display name from the local profile
                final Cursor cursor = context.getContentResolver().query(Profile.CONTENT_URI, new String[] { Phone._ID, Phone.DISPLAY_NAME }, null, null, null);
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            name = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME));
                        }
                    } finally {
                        cursor.close();
                    }
                }
            }
            return new Pair<String, Drawable>(name, avatar);
        }

        @Override
        protected void onPostExecute(Pair<String, Drawable> result) {
            super.onPostExecute(result);
            mModel.setUserTileInfo(result.first, result.second);
            mUserInfoTask = null;
        }
    };
    mUserInfoTask.execute();
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) LevelListDrawable(android.graphics.drawable.LevelListDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) UserInfo(android.content.pm.UserInfo) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Cursor(android.database.Cursor) Bitmap(android.graphics.Bitmap) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) RemoteException(android.os.RemoteException) Pair(android.util.Pair)

Aggregations

Pair (android.util.Pair)354 ArrayList (java.util.ArrayList)96 ArraySet (android.util.ArraySet)47 Point (android.graphics.Point)34 IOException (java.io.IOException)32 SSLContext (javax.net.ssl.SSLContext)32 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)31 Intent (android.content.Intent)30 RemoteException (android.os.RemoteException)29 UserHandle (android.os.UserHandle)23 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)23 Test (org.junit.Test)22 UserInfo (android.content.pm.UserInfo)19 File (java.io.File)19 HashMap (java.util.HashMap)19 ComponentName (android.content.ComponentName)18 Bundle (android.os.Bundle)17 PendingIntent (android.app.PendingIntent)16 Cursor (android.database.Cursor)15 Size (android.util.Size)15