Example usage for android.content.pm ServiceInfo ServiceInfo

List of usage examples for android.content.pm ServiceInfo ServiceInfo

Introduction

In this page you can find the example usage for android.content.pm ServiceInfo ServiceInfo.

Prototype

public ServiceInfo() 

Source Link

Usage

From source file:com.android.tv.util.TestUtils.java

public static ResolveInfo createResolveInfo(String packageName, String name) {
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.serviceInfo = new ServiceInfo();
    resolveInfo.serviceInfo.packageName = packageName;
    resolveInfo.serviceInfo.name = name;
    return resolveInfo;
}

From source file:com.test.onesignal.GenerateNotificationRunner.java

@Test
@Config(shadows = { ShadowOneSignal.class })
public void shouldFireNotificationExtenderService() throws Exception {
    // Test that GCM receiver starts the NotificationExtenderServiceTest when it is in the AndroidManifest.xml
    Bundle bundle = getBaseNotifBundle();

    Intent serviceIntent = new Intent();
    serviceIntent.setPackage("com.onesignal.example");
    serviceIntent.setAction("com.onesignal.NotificationExtender");
    ResolveInfo resolveInfo = new ResolveInfo();
    resolveInfo.serviceInfo = new ServiceInfo();
    resolveInfo.serviceInfo.name = "com.onesignal.example.NotificationExtenderServiceTest";
    RuntimeEnvironment.getRobolectricPackageManager().addResolveInfoForIntent(serviceIntent, resolveInfo);

    boolean ret = OneSignalPackagePrivateHelper.GcmBroadcastReceiver_processBundle(blankActivity, bundle);
    Assert.assertTrue(ret);/*from  www .ja va 2  s  .  c  o m*/

    Intent intent = Shadows.shadowOf(blankActivity).getNextStartedService();
    Assert.assertEquals("com.onesignal.NotificationExtender", intent.getAction());

    // Test that all options are set.
    NotificationExtenderServiceTest service = (NotificationExtenderServiceTest) startNotificationExtender(
            createInternalPayloadBundle(getBundleWithAllOptionsSet()), NotificationExtenderServiceTest.class);

    OSNotificationReceivedResult notificationReceived = service.notification;
    OSNotificationPayload notificationPayload = notificationReceived.payload;
    Assert.assertEquals("Test H", notificationPayload.title);
    Assert.assertEquals("Test B", notificationPayload.body);
    Assert.assertEquals("9764eaeb-10ce-45b1-a66d-8f95938aaa51", notificationPayload.notificationID);

    Assert.assertEquals(0, notificationPayload.lockScreenVisibility);
    Assert.assertEquals("FF0000FF", notificationPayload.smallIconAccentColor);
    Assert.assertEquals("703322744261", notificationPayload.fromProjectNumber);
    Assert.assertEquals("FFFFFF00", notificationPayload.ledColor);
    Assert.assertEquals("big_picture", notificationPayload.bigPicture);
    Assert.assertEquals("large_icon", notificationPayload.largeIcon);
    Assert.assertEquals("small_icon", notificationPayload.smallIcon);
    Assert.assertEquals("test_sound", notificationPayload.sound);
    Assert.assertEquals("You test $[notif_count] MSGs!", notificationPayload.groupMessage);
    Assert.assertEquals("http://google.com", notificationPayload.launchURL);
    Assert.assertEquals(10, notificationPayload.priority);
    Assert.assertEquals("a_key", notificationPayload.collapseId);

    Assert.assertEquals("id1", notificationPayload.actionButtons.get(0).id);
    Assert.assertEquals("button1", notificationPayload.actionButtons.get(0).text);
    Assert.assertEquals("ic_menu_share", notificationPayload.actionButtons.get(0).icon);
    Assert.assertEquals("id2", notificationPayload.actionButtons.get(1).id);
    Assert.assertEquals("button2", notificationPayload.actionButtons.get(1).text);
    Assert.assertEquals("ic_menu_send", notificationPayload.actionButtons.get(1).icon);

    Assert.assertEquals("test_image_url", notificationPayload.backgroundImageLayout.image);
    Assert.assertEquals("FF000000", notificationPayload.backgroundImageLayout.titleTextColor);
    Assert.assertEquals("FFFFFFFF", notificationPayload.backgroundImageLayout.bodyTextColor);

    JSONObject additionalData = notificationPayload.additionalData;
    Assert.assertEquals("myValue", additionalData.getString("myKey"));
    Assert.assertEquals("nValue", additionalData.getJSONObject("nested").getString("nKey"));

    Assert.assertNotSame(-1, service.notificationId);

    // Test a basic notification without anything special.
    startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle()),
            NotificationExtenderServiceTest.class);
    Assert.assertFalse(ShadowOneSignal.messages.contains("Error assigning"));

    // Test that a notification is still displayed if the developer's code in onNotificationProcessing throws an Exception.
    NotificationExtenderServiceTest.throwInAppCode = true;
    startNotificationExtender(createInternalPayloadBundle(getBaseNotifBundle("NewUUID1")),
            NotificationExtenderServiceTest.class);

    Assert.assertTrue(ShadowOneSignal.messages.contains("onNotificationProcessing throw an exception"));
    Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
    Assert.assertEquals(3, postedNotifs.size());
}

From source file:android.content.pm.PackageParser.java

private Service parseService(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs, int flags,
        String[] outError) throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestService);

    if (mParseServiceArgs == null) {
        mParseServiceArgs = new ParseComponentArgs(owner, outError,
                com.android.internal.R.styleable.AndroidManifestService_name,
                com.android.internal.R.styleable.AndroidManifestService_label,
                com.android.internal.R.styleable.AndroidManifestService_icon,
                com.android.internal.R.styleable.AndroidManifestService_logo,
                com.android.internal.R.styleable.AndroidManifestService_banner, mSeparateProcesses,
                com.android.internal.R.styleable.AndroidManifestService_process,
                com.android.internal.R.styleable.AndroidManifestService_description,
                com.android.internal.R.styleable.AndroidManifestService_enabled);
        mParseServiceArgs.tag = "<service>";
    }// www . j av  a 2s  . c  om

    mParseServiceArgs.sa = sa;
    mParseServiceArgs.flags = flags;

    Service s = new Service(mParseServiceArgs, new ServiceInfo());
    if (outError[0] != null) {
        sa.recycle();
        return null;
    }

    boolean setExported = sa.hasValue(com.android.internal.R.styleable.AndroidManifestService_exported);
    if (setExported) {
        s.info.exported = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_exported,
                false);
    }

    String str = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestService_permission, 0);
    if (str == null) {
        s.info.permission = owner.applicationInfo.permission;
    } else {
        s.info.permission = str.length() > 0 ? str.toString().intern() : null;
    }

    s.info.flags = 0;
    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_stopWithTask, false)) {
        s.info.flags |= ServiceInfo.FLAG_STOP_WITH_TASK;
    }
    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_isolatedProcess, false)) {
        s.info.flags |= ServiceInfo.FLAG_ISOLATED_PROCESS;
    }
    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestService_singleUser, false)) {
        s.info.flags |= ServiceInfo.FLAG_SINGLE_USER;
        if (s.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) {
            Slog.w(TAG, "Service exported request ignored due to singleUser: " + s.className + " at "
                    + mArchiveSourcePath + " " + parser.getPositionDescription());
            s.info.exported = false;
            setExported = true;
        }
    }

    sa.recycle();

    if ((owner.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) {
        // A heavy-weight application can not have services in its main process
        // We can do direct compare because we intern all strings.
        if (s.info.processName == owner.packageName) {
            outError[0] = "Heavy-weight applications can not have services in main process";
            return null;
        }
    }

    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getName().equals("intent-filter")) {
            ServiceIntentInfo intent = new ServiceIntentInfo(s);
            if (!parseIntent(res, parser, attrs, true, false, intent, outError)) {
                return null;
            }

            s.intents.add(intent);
        } else if (parser.getName().equals("meta-data")) {
            if ((s.metaData = parseMetaData(res, parser, attrs, s.metaData, outError)) == null) {
                return null;
            }
        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Unknown element under <service>: " + parser.getName() + " at " + mArchiveSourcePath
                        + " " + parser.getPositionDescription());
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                outError[0] = "Bad element under <service>: " + parser.getName();
                return null;
            }
        }
    }

    if (!setExported) {
        s.info.exported = s.intents.size() > 0;
    }

    return s;
}