Loading AndroidManifest.xml +11 −0 Original line number Diff line number Diff line Loading @@ -645,5 +645,16 @@ android:name=".calllog.CallLogNotificationsService" android:exported="false" /> <!-- Service that is exclusively for the Phone application that sends out a view notification. This service might be removed in future versions of the app --> <service android:name=".ViewNotificationService" android:permission="android.permission.WRITE_CONTACTS" android:exported="true"> <intent-filter> <action android:name="com.android.contacts.VIEW_NOTIFICATION" /> <data android:mimeType="vnd.android.cursor.item/contact" /> </intent-filter> </service> </application> </manifest> src/com/android/contacts/ViewNotificationService.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.contacts; import com.android.contacts.ContactLoader.Result; import android.app.Service; import android.content.Intent; import android.content.Loader; import android.content.Loader.OnLoadCompleteListener; import android.os.IBinder; import android.util.Log; /** * Service that sends out a view notification for a contact. At the moment, this is only * supposed to be used by the Phone app */ public class ViewNotificationService extends Service { private static final String TAG = ViewNotificationService.class.getSimpleName(); private static final boolean DEBUG = false; @Override public int onStartCommand(Intent intent, int flags, final int startId) { if (DEBUG) { Log.d(TAG, "onHandleIntent(). Intent: " + intent); } // We simply need to start a Loader here. When its done, it will send out the // View-Notification automatically. final ContactLoader contactLoader = new ContactLoader(this, intent.getData()); contactLoader.registerListener(0, new OnLoadCompleteListener<ContactLoader.Result>() { @Override public void onLoadComplete(Loader<Result> loader, Result data) { try { loader.reset(); } catch (RuntimeException e) { Log.e(TAG, "Error reseting loader", e); } try { // This is not 100% accurate actually. If we get several calls quickly, // we might be stopping out-of-order, in which case the call with the last // startId will stop this service. In practice, this shouldn't be a problem, // as this service is supposed to be called by the Phone app which only sends // out the notification once per phonecall. And even if there is a problem, // the worst that should happen is a missing view notification stopSelfResult(startId); } catch (RuntimeException e) { Log.e(TAG, "Error stopping service", e); } } }); contactLoader.startLoading(); return START_REDELIVER_INTENT; } @Override public IBinder onBind(Intent intent) { return null; } } src/com/android/contacts/socialwidget/SocialWidgetProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class SocialWidgetProvider extends AppWidgetProvider { ContactLoader loader = sLoaders.get(appWidgetId); if (loader != null) { Log.d(TAG, "Stopping loader for widget with id=" + appWidgetId); loader.stopLoading(); loader.reset(); sLoaders.delete(appWidgetId); } } Loading Loading
AndroidManifest.xml +11 −0 Original line number Diff line number Diff line Loading @@ -645,5 +645,16 @@ android:name=".calllog.CallLogNotificationsService" android:exported="false" /> <!-- Service that is exclusively for the Phone application that sends out a view notification. This service might be removed in future versions of the app --> <service android:name=".ViewNotificationService" android:permission="android.permission.WRITE_CONTACTS" android:exported="true"> <intent-filter> <action android:name="com.android.contacts.VIEW_NOTIFICATION" /> <data android:mimeType="vnd.android.cursor.item/contact" /> </intent-filter> </service> </application> </manifest>
src/com/android/contacts/ViewNotificationService.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 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.contacts; import com.android.contacts.ContactLoader.Result; import android.app.Service; import android.content.Intent; import android.content.Loader; import android.content.Loader.OnLoadCompleteListener; import android.os.IBinder; import android.util.Log; /** * Service that sends out a view notification for a contact. At the moment, this is only * supposed to be used by the Phone app */ public class ViewNotificationService extends Service { private static final String TAG = ViewNotificationService.class.getSimpleName(); private static final boolean DEBUG = false; @Override public int onStartCommand(Intent intent, int flags, final int startId) { if (DEBUG) { Log.d(TAG, "onHandleIntent(). Intent: " + intent); } // We simply need to start a Loader here. When its done, it will send out the // View-Notification automatically. final ContactLoader contactLoader = new ContactLoader(this, intent.getData()); contactLoader.registerListener(0, new OnLoadCompleteListener<ContactLoader.Result>() { @Override public void onLoadComplete(Loader<Result> loader, Result data) { try { loader.reset(); } catch (RuntimeException e) { Log.e(TAG, "Error reseting loader", e); } try { // This is not 100% accurate actually. If we get several calls quickly, // we might be stopping out-of-order, in which case the call with the last // startId will stop this service. In practice, this shouldn't be a problem, // as this service is supposed to be called by the Phone app which only sends // out the notification once per phonecall. And even if there is a problem, // the worst that should happen is a missing view notification stopSelfResult(startId); } catch (RuntimeException e) { Log.e(TAG, "Error stopping service", e); } } }); contactLoader.startLoading(); return START_REDELIVER_INTENT; } @Override public IBinder onBind(Intent intent) { return null; } }
src/com/android/contacts/socialwidget/SocialWidgetProvider.java +1 −1 Original line number Diff line number Diff line Loading @@ -76,7 +76,7 @@ public class SocialWidgetProvider extends AppWidgetProvider { ContactLoader loader = sLoaders.get(appWidgetId); if (loader != null) { Log.d(TAG, "Stopping loader for widget with id=" + appWidgetId); loader.stopLoading(); loader.reset(); sLoaders.delete(appWidgetId); } } Loading