use of android.content.IContentProvider 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;
}
use of android.content.IContentProvider 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();
}
}
use of android.content.IContentProvider 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();
}
}
use of android.content.IContentProvider in project android_frameworks_base by crdroidandroid.
the class ActivityThread method acquireExistingProvider.
public final IContentProvider acquireExistingProvider(Context c, ProviderKey key, boolean stable) {
synchronized (mProviderMap) {
final ProviderClientRecord pr = mProviderMap.get(key);
if (pr == null) {
return null;
}
IContentProvider provider = pr.mProvider;
IBinder jBinder = provider.asBinder();
if (!jBinder.isBinderAlive()) {
// The hosting process of the provider has died; we can't
// use this one.
Log.i(TAG, "Acquiring provider " + key.authority + " for user " + key.userId + ": existing object's process dead");
handleUnstableProviderDiedLocked(jBinder, true);
return null;
}
// Only increment the ref count if we have one. If we don't then the
// provider is not reference counted and never needs to be released.
ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
if (prc != null) {
incProviderRefLocked(prc, stable);
}
return provider;
}
}
use of android.content.IContentProvider in project android_frameworks_base by crdroidandroid.
the class ActivityThread method installProvider.
/**
* Installs the provider.
*
* Providers that are local to the process or that come from the system server
* may be installed permanently which is indicated by setting noReleaseNeeded to true.
* Other remote providers are reference counted. The initial reference count
* for all reference counted providers is one. Providers that are not reference
* counted do not have a reference count (at all).
*
* This method detects when a provider has already been installed. When this happens,
* it increments the reference count of the existing provider (if appropriate)
* and returns the existing provider. This can happen due to concurrent
* attempts to acquire the same provider.
*/
private IActivityManager.ContentProviderHolder installProvider(Context context, IActivityManager.ContentProviderHolder holder, ProviderInfo info, boolean noisy, boolean noReleaseNeeded, boolean stable) {
ContentProvider localProvider = null;
IContentProvider provider;
if (holder == null || holder.provider == null) {
if (DEBUG_PROVIDER || noisy) {
Slog.d(TAG, "Loading provider " + info.authority + ": " + info.name);
}
Context c = null;
ApplicationInfo ai = info.applicationInfo;
if (context.getPackageName().equals(ai.packageName)) {
c = context;
} else if (mInitialApplication != null && mInitialApplication.getPackageName().equals(ai.packageName)) {
c = mInitialApplication;
} else {
try {
c = context.createPackageContext(ai.packageName, Context.CONTEXT_INCLUDE_CODE);
} catch (PackageManager.NameNotFoundException e) {
// Ignore
}
}
if (c == null) {
Slog.w(TAG, "Unable to get context for package " + ai.packageName + " while loading content provider " + info.name);
return null;
}
try {
final java.lang.ClassLoader cl = c.getClassLoader();
localProvider = (ContentProvider) cl.loadClass(info.name).newInstance();
provider = localProvider.getIContentProvider();
if (provider == null) {
Slog.e(TAG, "Failed to instantiate class " + info.name + " from sourceDir " + info.applicationInfo.sourceDir);
return null;
}
if (DEBUG_PROVIDER)
Slog.v(TAG, "Instantiating local provider " + info.name);
// XXX Need to create the correct context for this provider.
localProvider.attachInfo(c, info);
} catch (java.lang.Exception e) {
if (!mInstrumentation.onException(null, e)) {
throw new RuntimeException("Unable to get provider " + info.name + ": " + e.toString(), e);
}
return null;
}
} else {
provider = holder.provider;
if (DEBUG_PROVIDER)
Slog.v(TAG, "Installing external provider " + info.authority + ": " + info.name);
}
IActivityManager.ContentProviderHolder retHolder;
synchronized (mProviderMap) {
if (DEBUG_PROVIDER)
Slog.v(TAG, "Checking to add " + provider + " / " + info.name);
IBinder jBinder = provider.asBinder();
if (localProvider != null) {
ComponentName cname = new ComponentName(info.packageName, info.name);
ProviderClientRecord pr = mLocalProvidersByName.get(cname);
if (pr != null) {
if (DEBUG_PROVIDER) {
Slog.v(TAG, "installProvider: lost the race, " + "using existing local provider");
}
provider = pr.mProvider;
} else {
holder = new IActivityManager.ContentProviderHolder(info);
holder.provider = provider;
holder.noReleaseNeeded = true;
pr = installProviderAuthoritiesLocked(provider, localProvider, holder);
mLocalProviders.put(jBinder, pr);
mLocalProvidersByName.put(cname, pr);
}
retHolder = pr.mHolder;
} else {
ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
if (prc != null) {
if (DEBUG_PROVIDER) {
Slog.v(TAG, "installProvider: lost the race, updating ref count");
}
// system process).
if (!noReleaseNeeded) {
incProviderRefLocked(prc, stable);
try {
ActivityManagerNative.getDefault().removeContentProvider(holder.connection, stable);
} catch (RemoteException e) {
//do nothing content provider object is dead any way
}
}
} else {
ProviderClientRecord client = installProviderAuthoritiesLocked(provider, localProvider, holder);
if (noReleaseNeeded) {
prc = new ProviderRefCount(holder, client, 1000, 1000);
} else {
prc = stable ? new ProviderRefCount(holder, client, 1, 0) : new ProviderRefCount(holder, client, 0, 1);
}
mProviderRefCountMap.put(jBinder, prc);
}
retHolder = prc.holder;
}
}
return retHolder;
}
Aggregations