Search in sources :

Example 6 with ContentProviderHolder

use of android.app.IActivityManager.ContentProviderHolder in project android_frameworks_base by ResurrectionRemix.

the class ContentProviderRecord method newHolder.

public ContentProviderHolder newHolder(ContentProviderConnection conn) {
    ContentProviderHolder holder = new ContentProviderHolder(info);
    holder.provider = provider;
    holder.noReleaseNeeded = noReleaseNeeded;
    holder.connection = conn;
    return holder;
}
Also used : ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder)

Example 7 with ContentProviderHolder

use of android.app.IActivityManager.ContentProviderHolder in project android_frameworks_base by ResurrectionRemix.

the class ShellUiAutomatorBridge method getSystemLongPressTime.

public long getSystemLongPressTime() {
    // Read the long press timeout setting.
    long longPressTimeout = 0;
    try {
        IContentProvider provider = null;
        Cursor cursor = null;
        IActivityManager activityManager = ActivityManagerNative.getDefault();
        String providerName = Settings.Secure.CONTENT_URI.getAuthority();
        IBinder token = new Binder();
        try {
            ContentProviderHolder holder = activityManager.getContentProviderExternal(providerName, UserHandle.USER_SYSTEM, token);
            if (holder == null) {
                throw new IllegalStateException("Could not find provider: " + providerName);
            }
            provider = holder.provider;
            cursor = provider.query(null, Settings.Secure.CONTENT_URI, new String[] { Settings.Secure.VALUE }, "name=?", new String[] { Settings.Secure.LONG_PRESS_TIMEOUT }, null, null);
            if (cursor.moveToFirst()) {
                longPressTimeout = cursor.getInt(0);
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (provider != null) {
                activityManager.removeContentProviderExternal(providerName, token);
            }
        }
    } catch (RemoteException e) {
        String message = "Error reading long press timeout setting.";
        Log.e(LOG_TAG, message, e);
        throw new RuntimeException(message, e);
    }
    return longPressTimeout;
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider) ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 8 with ContentProviderHolder

use of android.app.IActivityManager.ContentProviderHolder in project android_frameworks_base by ResurrectionRemix.

the class SettingsCmd method run.

public void run() {
    boolean valid = false;
    String arg;
    try {
        while ((arg = nextArg()) != null) {
            if ("--user".equals(arg)) {
                if (mUser != -1) {
                    // --user specified more than once; invalid
                    break;
                }
                arg = nextArg();
                if ("current".equals(arg) || "cur".equals(arg)) {
                    mUser = UserHandle.USER_CURRENT;
                } else {
                    mUser = Integer.parseInt(arg);
                }
            } else if ("--cm".equals(arg)) {
                mUseCMSettingsProvider = true;
            } else if (mVerb == CommandVerb.UNSPECIFIED) {
                if ("get".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.GET;
                } else if ("put".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.PUT;
                } else if ("delete".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.DELETE;
                } else if ("list".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.LIST;
                } else {
                    // invalid
                    System.err.println("Invalid command: " + arg);
                    break;
                }
            } else if (mTable == null) {
                if (!"system".equalsIgnoreCase(arg) && !"secure".equalsIgnoreCase(arg) && !"global".equalsIgnoreCase(arg)) {
                    System.err.println("Invalid namespace '" + arg + "'");
                    // invalid
                    break;
                }
                mTable = arg.toLowerCase();
                if (mVerb == CommandVerb.LIST) {
                    valid = true;
                    break;
                }
            } else if (mVerb == CommandVerb.GET || mVerb == CommandVerb.DELETE) {
                mKey = arg;
                if (mNextArg >= mArgs.length) {
                    valid = true;
                } else {
                    System.err.println("Too many arguments");
                }
                break;
            } else if (mKey == null) {
                mKey = arg;
            // keep going; there's another PUT arg
            } else {
                // PUT, final arg
                mValue = arg;
                if (mNextArg >= mArgs.length) {
                    valid = true;
                } else {
                    System.err.println("Too many arguments");
                }
                break;
            }
        }
    } catch (Exception e) {
        valid = false;
    }
    if (valid) {
        try {
            IActivityManager activityManager = ActivityManagerNative.getDefault();
            if (mUser == UserHandle.USER_CURRENT) {
                mUser = activityManager.getCurrentUser().id;
            }
            if (mUser < 0) {
                mUser = UserHandle.USER_SYSTEM;
            }
            IContentProvider provider = null;
            IBinder token = new Binder();
            try {
                ContentProviderHolder holder = activityManager.getContentProviderExternal(mUseCMSettingsProvider ? CMSettings.AUTHORITY : Settings.AUTHORITY, UserHandle.USER_SYSTEM, token);
                if (holder == null) {
                    throw new IllegalStateException("Could not find settings provider");
                }
                provider = holder.provider;
                switch(mVerb) {
                    case GET:
                        System.out.println(getForUser(provider, mUser, mTable, mKey));
                        break;
                    case PUT:
                        putForUser(provider, mUser, mTable, mKey, mValue);
                        break;
                    case DELETE:
                        System.out.println("Deleted " + deleteForUser(provider, mUser, mTable, mKey) + " rows");
                        break;
                    case LIST:
                        for (String line : listForUser(provider, mUser, mTable)) {
                            System.out.println(line);
                        }
                        break;
                    default:
                        System.err.println("Unspecified command");
                        break;
                }
            } finally {
                if (provider != null) {
                    activityManager.removeContentProviderExternal("settings", token);
                }
            }
        } catch (Exception e) {
            System.err.println("Error while accessing settings provider");
            e.printStackTrace();
        }
    } else {
        printUsage();
    }
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider) ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 9 with ContentProviderHolder

use of android.app.IActivityManager.ContentProviderHolder in project android_frameworks_base by crdroidandroid.

the class SettingsCmd method run.

public void run() {
    boolean valid = false;
    String arg;
    try {
        while ((arg = nextArg()) != null) {
            if ("--user".equals(arg)) {
                if (mUser != -1) {
                    // --user specified more than once; invalid
                    break;
                }
                arg = nextArg();
                if ("current".equals(arg) || "cur".equals(arg)) {
                    mUser = UserHandle.USER_CURRENT;
                } else {
                    mUser = Integer.parseInt(arg);
                }
            } else if ("--cm".equals(arg)) {
                mUseCMSettingsProvider = true;
            } else if (mVerb == CommandVerb.UNSPECIFIED) {
                if ("get".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.GET;
                } else if ("put".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.PUT;
                } else if ("delete".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.DELETE;
                } else if ("list".equalsIgnoreCase(arg)) {
                    mVerb = CommandVerb.LIST;
                } else {
                    // invalid
                    System.err.println("Invalid command: " + arg);
                    break;
                }
            } else if (mTable == null) {
                if (!"system".equalsIgnoreCase(arg) && !"secure".equalsIgnoreCase(arg) && !"global".equalsIgnoreCase(arg)) {
                    System.err.println("Invalid namespace '" + arg + "'");
                    // invalid
                    break;
                }
                mTable = arg.toLowerCase();
                if (mVerb == CommandVerb.LIST) {
                    valid = true;
                    break;
                }
            } else if (mVerb == CommandVerb.GET || mVerb == CommandVerb.DELETE) {
                mKey = arg;
                if (mNextArg >= mArgs.length) {
                    valid = true;
                } else {
                    System.err.println("Too many arguments");
                }
                break;
            } else if (mKey == null) {
                mKey = arg;
            // keep going; there's another PUT arg
            } else {
                // PUT, final arg
                mValue = arg;
                if (mNextArg >= mArgs.length) {
                    valid = true;
                } else {
                    System.err.println("Too many arguments");
                }
                break;
            }
        }
    } catch (Exception e) {
        valid = false;
    }
    if (valid) {
        try {
            IActivityManager activityManager = ActivityManagerNative.getDefault();
            if (mUser == UserHandle.USER_CURRENT) {
                mUser = activityManager.getCurrentUser().id;
            }
            if (mUser < 0) {
                mUser = UserHandle.USER_SYSTEM;
            }
            IContentProvider provider = null;
            IBinder token = new Binder();
            try {
                ContentProviderHolder holder = activityManager.getContentProviderExternal(mUseCMSettingsProvider ? CMSettings.AUTHORITY : Settings.AUTHORITY, UserHandle.USER_SYSTEM, token);
                if (holder == null) {
                    throw new IllegalStateException("Could not find settings provider");
                }
                provider = holder.provider;
                switch(mVerb) {
                    case GET:
                        System.out.println(getForUser(provider, mUser, mTable, mKey));
                        break;
                    case PUT:
                        putForUser(provider, mUser, mTable, mKey, mValue);
                        break;
                    case DELETE:
                        System.out.println("Deleted " + deleteForUser(provider, mUser, mTable, mKey) + " rows");
                        break;
                    case LIST:
                        for (String line : listForUser(provider, mUser, mTable)) {
                            System.out.println(line);
                        }
                        break;
                    default:
                        System.err.println("Unspecified command");
                        break;
                }
            } finally {
                if (provider != null) {
                    activityManager.removeContentProviderExternal("settings", token);
                }
            }
        } catch (Exception e) {
            System.err.println("Error while accessing settings provider");
            e.printStackTrace();
        }
    } else {
        printUsage();
    }
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider) ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 10 with ContentProviderHolder

use of android.app.IActivityManager.ContentProviderHolder in project android_frameworks_base by crdroidandroid.

the class ContentProviderRecord method newHolder.

public ContentProviderHolder newHolder(ContentProviderConnection conn) {
    ContentProviderHolder holder = new ContentProviderHolder(info);
    holder.provider = provider;
    holder.noReleaseNeeded = noReleaseNeeded;
    holder.connection = conn;
    return holder;
}
Also used : ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder)

Aggregations

ContentProviderHolder (android.app.IActivityManager.ContentProviderHolder)17 IActivityManager (android.app.IActivityManager)11 IContentProvider (android.content.IContentProvider)11 Binder (android.os.Binder)11 IBinder (android.os.IBinder)11 RemoteException (android.os.RemoteException)11 Cursor (android.database.Cursor)5