/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.PackageItemInfo; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.gadget.GadgetManager; import android.gadget.GadgetInfo; import android.os.Binder; import android.util.AttributeSet; import android.util.Log; import android.util.Xml; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import com.android.internal.gadget.IGadgetService; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; class GadgetService extends IGadgetService.Stub { private static final String TAG = "GadgetService"; static class GadgetId { int gadgetId; String hostPackage; GadgetInfo info; } Context mContext; PackageManager mPackageManager; ArrayList mInstalledProviders; int mNextGadgetId = 1; ArrayList mGadgetIds = new ArrayList(); GadgetService(Context context) { mContext = context; mPackageManager = context.getPackageManager(); mInstalledProviders = getGadgetList(); } @Override public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { if (mContext.checkCallingPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) { pw.println("Permission Denial: can't dump from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid()); return; } synchronized (mGadgetIds) { int N = mInstalledProviders.size(); pw.println("Providers: (size=" + N + ")"); for (int i=0; i getInstalledProviders() { synchronized (mGadgetIds) { return new ArrayList(mInstalledProviders); } } boolean canAccessGadgetId(GadgetId id, String callingPackage) { if (id.hostPackage.equals(callingPackage)) { return true; } if (id.info != null && id.info.provider.getPackageName().equals(callingPackage)) { return true; } // TODO: Check for the pick permission //if (has permission) { // return true; //} //return false; return true; } private GadgetId lookupGadgetIdLocked(int gadgetId) { String callingPackage = getCallingPackage(); final int N = mGadgetIds.size(); for (int i=0; i getGadgetList() { PackageManager pm = mPackageManager; // TODO: We have these as different actions. I wonder if it makes more sense to // have like a GADGET_ACTION, and then subcommands. It's kind of arbitrary that // we look for GADGET_UPDATE_ACTION and not any of the other gadget actions. Intent intent = new Intent(GadgetManager.GADGET_UPDATE_ACTION); List broadcastReceivers = pm.queryBroadcastReceivers(intent, PackageManager.GET_META_DATA); ArrayList result = new ArrayList(); final int N = broadcastReceivers.size(); for (int i=0; i