Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
FAT32 SHAMER
Aug 16, 2012



I think theres a bit of disappointment that they're pushing this instead of pushing something new that fixes all the issues developers face every day.

It's easier to post zingers about how this is smoke and mirrors to distract us for a while than it is to look at kotlin and be like "hmm maybe i'll use this one day when Im doing something that isnt critical"

Adbot
ADBOT LOVES YOU

FAT32 SHAMER
Aug 16, 2012



Ok guys I've been trying to figure this one out all day. I have a package name that I am trying to launch but I have neither the source code nor the main activity name to be able to launch it without simulating the click on screen using UiAutomator. Anyone have any ideas on how I would go about doing this? I saw someone on Stack Overflow say something about PackageManager but I couldnt parse what it was trying to say due to being in Hinglish.

Mezzanine
Aug 23, 2009

funny Star Wars parody posted:

I think theres a bit of disappointment that they're pushing this instead of pushing something new that fixes all the issues developers face every day.

I think it's worth it just for the "import kotlinx.android.synthetic.main.activity_foo.* " thing that handles all of the "private TextView mTextFoo;" and "mTextFoo = (TextView) findViewById(R.id.textFoo);" boilerplate with just one import line for the entire layout.

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

Mezzanine posted:

I think it's worth it just for the "import kotlinx.android.synthetic.main.activity_foo.* " thing that handles all of the "private TextView mTextFoo;" and "mTextFoo = (TextView) findViewById(R.id.textFoo);" boilerplate with just one import line for the entire layout.

if you want to win people over, maybe don't mention the fact that you're a fan of wildcard imports

Mezzanine
Aug 23, 2009

Lutha Mahtin posted:

if you want to win people over, maybe don't mention the fact that you're a fan of wildcard imports

So, import every single id in the layout I just wrote myself by hand?

Mezzanine fucked around with this message at 01:24 on May 31, 2017

Taffer
Oct 15, 2010


Lutha Mahtin posted:

if you want to win people over, maybe don't mention the fact that you're a fan of wildcard imports

What's wrong with a wildcard import on something with your own package name that you wrote yourself?

Lutha Mahtin
Oct 10, 2010

Your brokebrain sin is absolved...go and shitpost no more!

i honestly don't know how to respond to either of those posts. one of them implies that the poster only uses 1970s text editors without any kind of IDE functionality. the other implies the poster doesn't understand the basics of predicate logic. both of them defend wildcard imports. i'm really out of my depth in a situation where people are that ignorant and yet are insistent that their ignorance is correct and valid

Mezzanine
Aug 23, 2009

Lutha Mahtin posted:

i honestly don't know how to respond to either of those posts. one of them implies that the poster only uses 1970s text editors without any kind of IDE functionality. the other implies the poster doesn't understand the basics of predicate logic. both of them defend wildcard imports. i'm really out of my depth in a situation where people are that ignorant and yet are insistent that their ignorance is correct and valid

Thank you for your insightful response and detailed explanation of your initial comment! I'll make sure to put all of your thoughtful advice to good use! After all, that's what this thread is here for, right?

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

funny Star Wars parody posted:

Ok guys I've been trying to figure this one out all day. I have a package name that I am trying to launch but I have neither the source code nor the main activity name to be able to launch it without simulating the click on screen using UiAutomator. Anyone have any ideas on how I would go about doing this? I saw someone on Stack Overflow say something about PackageManager but I couldnt parse what it was trying to say due to being in Hinglish.

adb logcat ActivityManager:V *:F

Launch the app, you'll see what the package name and the path to the main activity are.

Otherwise, you can use aapt to dump the manifest contents to find the activity with the internet filter with MAIN in it.

Edit: with regard to IDs, your IDE will generally let you do static imports, which provides cleaner layout without accidental collisions/pollutions from other namespaces.

brap
Aug 23, 2004

Grimey Drawer

Lutha Mahtin posted:

i honestly don't know how to respond to either of those posts. one of them implies that the poster only uses 1970s text editors without any kind of IDE functionality. the other implies the poster doesn't understand the basics of predicate logic. both of them defend wildcard imports. i'm really out of my depth in a situation where people are that ignorant and yet are insistent that their ignorance is correct and valid

Honestly dude you are acting like a douche.

Mezzanine
Aug 23, 2009

Volmarias posted:

Edit: with regard to IDs, your IDE will generally let you do static imports, which provides cleaner layout without accidental collisions/pollutions from other namespaces.

Yeah, I do that in most cases (Android Studio / IntelliJ handles imports automatically quite well). This is a rather specific case where the "Kotlin addons plugin" provides all of the ids in a specific layout xml as an import. In many cases, an Activity / Fragment will only be using one layout so the wildcard would be fine. The other option is to have the IDE import them piecemeal as I reference them in code, which is what I do for anything not handwritten by myself.

b0lt
Apr 29, 2005

Lutha Mahtin posted:

one of them implies that the poster only uses 1970s text editors without any kind of IDE functionality

"my editor generates the meaningless boilerplate" is not a very compelling argument

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

adb logcat ActivityManager:V *:F

Launch the app, you'll see what the package name and the path to the main activity are.

Otherwise, you can use aapt to dump the manifest contents to find the activity with the internet filter with MAIN in it.

Edit: with regard to IDs, your IDE will generally let you do static imports, which provides cleaner layout without accidental collisions/pollutions from other namespaces.

Nice, thanks! I found this way of launching the package however I'm not sure why he's able to call the getPackageManager() and startActivity methods. I'm assuming it comes from a Context that is written somewhere else but I haven't written test code for a package I dont have the source code for before :shobon:

Java code:
try {
	Intent intent = getPackageManager().getLaunchIntentForPackage("com.missing.package.MAIN"]);
	startActivity(intent);
} catch (Exception e) {
    // returns null if application is not installed
}

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

funny Star Wars parody posted:

Nice, thanks! I found this way of launching the package however I'm not sure why he's able to call the getPackageManager() and startActivity methods. I'm assuming it comes from a Context that is written somewhere else but I haven't written test code for a package I dont have the source code for before :shobon:

Java code:

try {
	Intent intent = getPackageManager().getLaunchIntentForPackage("com.missing.package.MAIN"]);
	startActivity(intent);
} catch (Exception e) {
    // returns null if application is not installed
}

I assume that whatever class this is in extends context, or just also happened to have convenience methods for startActivity and getPackageManager. Without more info about where this code snippet lives I can't give you something better

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

funny Star Wars parody posted:

Nice, thanks! I found this way of launching the package however I'm not sure why he's able to call the getPackageManager() and startActivity methods. I'm assuming it comes from a Context that is written somewhere else but I haven't written test code for a package I dont have the source code for before :shobon:

This is in an instrumentation test? Can you use InstrumentationRegistry.getTargetContext() for it?

FAT32 SHAMER
Aug 16, 2012



baka kaba posted:

This is in an instrumentation test? Can you use InstrumentationRegistry.getTargetContext() for it?

This worked, at least for the other apps on this device! There is an app that will only launch when you hold three physical buttons for three seconds and even though I have the package name it simply won't launch, and UiAutomator can grab the XML for me to simulate click events once the app is launched. I'm starting to wonder if the app was written weird for it to do this

For the record this is a automobile head unit/nav unit that I'm working on automating testing for so that's why this has been such a bitch compared to abnormal phone/tablet

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

funny Star Wars parody posted:

This worked, at least for the other apps on this device! There is an app that will only launch when you hold three physical buttons for three seconds and even though I have the package name it simply won't launch, and UiAutomator can grab the XML for me to simulate click events once the app is launched. I'm starting to wonder if the app was written weird for it to do this

For the record this is a automobile head unit/nav unit that I'm working on automating testing for so that's why this has been such a bitch compared to abnormal phone/tablet

You can always launch an activity via an explicit intent, as long as you know what the activity name is, and as long as the activity is marked as exported.

I'm curious how they're doing the key press thing though, is possible that this head unit remapped that to the camera key or something.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Does it not launch at all, or does it start and immediately quit? They might have some weird Intent handler code that nopes out if you didn't launch it with the correct data

Unless, is the head unit already running that app as the UI? So it's capturing the keypresses and launching another 'app' that's really an internal component of the same app? Meaning the activity you're trying to launch might not actually be exported

FAT32 SHAMER
Aug 16, 2012



baka kaba posted:

Does it not launch at all, or does it start and immediately quit? They might have some weird Intent handler code that nopes out if you didn't launch it with the correct data

Unless, is the head unit already running that app as the UI? So it's capturing the keypresses and launching another 'app' that's really an internal component of the same app? Meaning the activity you're trying to launch might not actually be exported

It doesnt start at all and I get a "cannot call an intent from a null something something" error so I'm guessing the Intent is not exported :rip:


Volmarias posted:

You can always launch an activity via an explicit intent, as long as you know what the activity name is, and as long as the activity is marked as exported.

I'm curious how they're doing the key press thing though, is possible that this head unit remapped that to the camera key or something.

You press the Volume button + brightness button + home button for three seconds, I have no idea what they're overriding but it's pretty neato bandito :3:

(except for the part where i have to mark it as a semi-automated test instead of a fully automated test :argh:)

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

funny Star Wars parody posted:

It doesnt start at all and I get a "cannot call an intent from a null something something" error so I'm guessing the Intent is not exported :rip:

Redact the package name but post the error log here. What process gives that, the process you're trying to call, or the system_service?

Again, use logcat to parse ActivityManager logs to see what the entry Activity is. You can use an Explicit intent to start that activity, although how exactly you'll be testing is an open question.

kitten smoothie
Dec 29, 2001

Has anyone goofed with the architecture framework they rolled out at I/O and have opinions on it yet?

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

Redact the package name but post the error log here. What process gives that, the process you're trying to call, or the system_service?

Again, use logcat to parse ActivityManager logs to see what the entry Activity is. You can use an Explicit intent to start that activity, although how exactly you'll be testing is an open question.

code:
$ adb shell am instrument -w -r   -e debug false -e class com.group.benchautomation.DealerDiagsTest com.group.benchautomation.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.addFlags(int)' on a null object reference
at com.group.benchautomation.DealerDiagsTest.setup(DealerDiagsTest.java:56)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:59)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:262)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1853)

Tests ran to completion.
and here is the code from the area

Java code:
    @Before
    public void setup() {
        //Initialize UiDevice instance
        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
        mDevice = UiDevice.getInstance(instrumentation);

        mDevice.pressHome();

        final String launcherPackage = "com.REDACTED.auto.diagnostics";
        assertThat(launcherPackage, notNullValue());
        mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);

        Context context = InstrumentationRegistry.getContext();
        final Intent intent = context.getPackageManager()
                .getLaunchIntentForPackage(DEALER_DIAG_PACKAGE);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); //this is line 56
        context.startActivity(intent);

        mDevice.wait(Until.hasObject(By.pkg(DEALER_DIAG_PACKAGE).depth(0)), LAUNCH_TIMEOUT);
    }

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Well you're getting it from this

quote:

The current implementation looks first for a main activity in the category CATEGORY_INFO, and next for a main activity in the category CATEGORY_LAUNCHER. Returns null if neither are found.

This sounds like a pain in the :yayclod: to be honest!

FAT32 SHAMER
Aug 16, 2012



baka kaba posted:

Well you're getting it from this


This sounds like a pain in the :yayclod: to be honest!

Nah it just means instead of trying to launch it via an activity i will have to use a CAN database to simulate the signal that pressing the button does. The same thing happens when I try to launch the HVAC settings via activity instead of hitting the hard button, which tells me that it only wants a CAN/MOST signal instead of pure android implementation

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
:psyduck:

Again, look for the exported activity that gets launched when you press those buttons and specify it manually. Use setClassName to specify what you want to launch. You don't need to pick the one that would show up in the launcher, since you already told us it won't.

If the package doesn't export any activities (due to catching a signal via broadcast intent or some other fuckery) then realistically you truly are hosed, but please start by finding the activity that you're trying to test.

Volmarias fucked around with this message at 02:59 on Jun 3, 2017

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

:psyduck:

Again, look for the exported activity that gets launched when you press those buttons and specify it manually. Use setClassName to specify what you want to launch. You don't need to pick the one that would show up in the launcher, since you already told us it won't.

I tried every package name that the logcat spat out and none of them worked :shrug:

Are package names supposed to have slashes like com.bench.tuner/AMTuner or do I have to do some kind of string handling to handle the / character

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

funny Star Wars parody posted:

I tried every package name that the logcat spat out and none of them worked :shrug:

Are package names supposed to have slashes like com.bench.tuner/AMTuner or do I have to do some kind of string handling to handle the / character

The slash delineates the package name from the activity. Rather than repeating the entire package name, it strips the part that's already been provided. So, com.foo.bar with an activity at com.foo.bar.main.Butts would be represented as com.foo.bar/.main.Butts (I think it's .main and not main, but confirm this yourself)

Alternately, if you can get the apk itself, use aapt dump to dump out the (data representation of the) AndroidManifest file

Alternately, ADB dumpsys package will give you more than you ever wanted to know, but your info might show up there.

Volmarias fucked around with this message at 05:02 on Jun 3, 2017

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

The slash delineates the package name from the activity. Rather than repeating the entire package name, it strips the part that's already been provided. So, com.foo.bar with an activity at com.foo.bar.main.Butts would be represented as com.foo.bar/.main.Butts (I think it's .main and not main, but confirm this yourself)

Alternately, if you can get the apk itself, use aapt dump to dump out the (data representation of the) AndroidManifest file

Alternately, ADB dumpsys package will give you more than you ever wanted to know, but your info might show up there.

I'll have to check it out on monday and see if I can figure anything else out. I wont be able to get any source code from the client and with how modified the OS appears to be I'm guessing that i'm in some uncharted waters and will have to do it the hard way

FAT32 SHAMER
Aug 16, 2012



Ok here's the adb logcat ActivityManager:V *:F log dump when I launch the hidden app using button presses.

code:
--------- beginning of main
I/ActivityManager( 2296): START u0 {flg=0x10000000 cmp=com.android.systemui/.usb.UsbDebuggingActivity (has extras)} from uid 1000 on display 0
I/ActivityManager( 2296): Displayed com.android.systemui/.usb.UsbDebuggingActivity: +184ms
I/ActivityManager( 2296): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher3/.Launcher} from uid 1000 on display 0
I/ActivityManager( 2296): START u0 {act=com.REDACTED.auto.diagnostics.dealer.MAIN flg=0x10800000 cmp=com.REDACTED.auto.diagnostics/.dealer.MainActivity} from uid 1000 on display 0
I/ActivityManager( 2296): Start proc 20943:com.REDACTED.auto.diagnostics/1000 for activity com.REDACTED.auto.diagnostics/.dealer.MainActivity
I/ActivityManager( 2296): Displayed com.REDACTED.auto.diagnostics/.dealer.MainActivity: +572ms
Oddly the way they have their package names when i launch the AM app vs the FM app via intents/activities

code:
I/ActivityManager( 2296): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x34204000 cmp=com.REDACTED.tuner/.ui.FMActivity bnds=[374,117][608,331] (has extras)} from uid 1000 on display 0
I/ActivityManager( 2296): Displayed com.REDACTED.tuner/.ui.FMActivity: +544ms
I/ActivityManager( 2296): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.android.launcher3/.Launcher} from uid 1000 on display 0
I/ActivityManager( 2296): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x34204000 cmp=com.REDACTED.tuner/.ui.AMActivity bnds=[890,117][1124,331] (has extras)} from uid 1000 on display 0
I/ActivityManager( 2296): Displayed com.REDACTED.tuner/.ui.AMActivity: +285ms

When I launch the com.REDACTED.tuner it will launch the AM tuner, however it crashes with a null object exception when i try to launch using com.REDACTED.tuner/.ui.AMActivity or com.REDACTED.tuner/.ui.FMActivity from my instrumentation tests. I tried removing the slashes from the package names as well but with no luck

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

I saw you're using getContext() - did you try getTargetContext() instead? I'm not sure exactly how it will work for what you're doing, but the target context is for the thing under instrumentation, instead of the thing running the tests

FAT32 SHAMER
Aug 16, 2012



baka kaba posted:

I saw you're using getContext() - did you try getTargetContext() instead? I'm not sure exactly how it will work for what you're doing, but the target context is for the thing under instrumentation, instead of the thing running the tests

Hmm, that seems to be giving me the same java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.addFlags(int)' on a null object reference. Google hasnt exactly been very helpful in looking for clues on this one either so i'm not 100% sure.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Do this to start the diagnostics app:
code:
Intent intent = new Intent("com.REDACTED.auto.diagnostics.dealer.MAIN");
intent.setClassName("com.REDACTED.auto.diagnostics", "com.REDACTED.auto.diagnostics.dealer.MainActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
Context c = InstrumentationRegistry.getContext();
c.startActivity(intent);
Also

funny Star Wars parody posted:

Hmm, that seems to be giving me the same java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.addFlags(int)' on a null object reference. Google hasnt exactly been very helpful in looking for clues on this one either so i'm not 100% sure.

The error is exactly what it says. You can't call the "addFlags" instance method on a null instance. Your intent doesn't exist, that's the problem. There IS NO LAUNCH ACTIVITY (as far launchers are concerned) for this app. If you haven't yet learned how to, I highly recommend learning how to use the debugger.

Edit: to further clarify, here's the source for getLaunchIntentForPackage, which you should not be using here because there is no launch activity:
code:
    @Override
    public Intent getLaunchIntentForPackage(String packageName) {
        // First see if the package has an INFO activity; the existence of
        // such an activity is implied to be the desired front-door for the
        // overall package (such as if it has multiple launcher entries).
        Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
        intentToResolve.addCategory(Intent.CATEGORY_INFO);
        intentToResolve.setPackage(packageName);
        List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);

        // Otherwise, try to find a main launcher activity.
        if (ris == null || ris.size() <= 0) {
            // reuse the intent instance
            intentToResolve.removeCategory(Intent.CATEGORY_INFO);
            intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
            intentToResolve.setPackage(packageName);
            ris = queryIntentActivities(intentToResolve, 0);
        }
        if (ris == null || ris.size() <= 0) {
            return null;
        }
        Intent intent = new Intent(intentToResolve);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClassName(ris.get(0).activityInfo.packageName,
                ris.get(0).activityInfo.name);
        return intent;
    }
If the package doesn't have an activity with an intent filter for CATEGORY_INFO or CATEGORY_LAUNCHER, it returns null. This is why I kept telling you to glean the ACTUAL activity name / package name (and the action is a nice bonus) from the ActivityManager logcat output: It tells you what to actually invoke.

Now, mind you, it's possible that there are some extras in the intent that need to be provided, so unless you have root on the test device and can pull the target app to examine it, or flash a debug build which shows all of the intent info, you might still be SOL. That said, why haven't you contacted the OEM for info yet?

Volmarias fucked around with this message at 19:05 on Jun 6, 2017

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

Do this to start the diagnostics app:
code:
Intent intent = new Intent("com.REDACTED.auto.diagnostics.dealer.MAIN");
intent.setClassName("com.REDACTED.auto.diagnostics", "com.REDACTED.auto.diagnostics.dealer.MainActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
Context c = InstrumentationRegistry.getContext();
c.startActivity(intent);
Also


The error is exactly what it says. You can't call the "addFlags" instance method on a null instance. Your intent doesn't exist, that's the problem. There IS NO LAUNCH ACTIVITY (as far launchers are concerned) for this app. If you haven't yet learned how to, I highly recommend learning how to use the debugger.

Edit: to further clarify, here's the source for getLaunchIntentForPackage, which you should not be using here because there is no launch activity:
code:
    @Override
    public Intent getLaunchIntentForPackage(String packageName) {
        // First see if the package has an INFO activity; the existence of
        // such an activity is implied to be the desired front-door for the
        // overall package (such as if it has multiple launcher entries).
        Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
        intentToResolve.addCategory(Intent.CATEGORY_INFO);
        intentToResolve.setPackage(packageName);
        List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);

        // Otherwise, try to find a main launcher activity.
        if (ris == null || ris.size() <= 0) {
            // reuse the intent instance
            intentToResolve.removeCategory(Intent.CATEGORY_INFO);
            intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
            intentToResolve.setPackage(packageName);
            ris = queryIntentActivities(intentToResolve, 0);
        }
        if (ris == null || ris.size() <= 0) {
            return null;
        }
        Intent intent = new Intent(intentToResolve);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setClassName(ris.get(0).activityInfo.packageName,
                ris.get(0).activityInfo.name);
        return intent;
    }
If the package doesn't have an activity with an intent filter for CATEGORY_INFO or CATEGORY_LAUNCHER, it returns null. This is why I kept telling you to glean the ACTUAL activity name / package name (and the action is a nice bonus) from the ActivityManager logcat output: It tells you what to actually invoke.

Now, mind you, it's possible that there are some extras in the intent that need to be provided, so unless you have root on the test device and can pull the target app to examine it, or flash a debug build which shows all of the intent info, you might still be SOL. That said, why haven't you contacted the OEM for info yet?
The OEM unfortunately will not discuss their system with me for reasons unknown, my guess is because the designers only speak japanese and it's not worth the effort when I'm working on something that wont necessarily benefit them as much as it benefits third parties.

That being said, the only fix I had to add was intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) after the clear task flag method call to get this to work :dance:. I wish I had caught on to your hints sooner, I didnt realize that you could specify intent class names using the .setClassName() method and google is wicked sparse on the details for doing anything with AndroidJUnit/UiAutomator for some reason (i'm assuming because most places have smarter people than me to figure it out :downs:)

Thanks for this!

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

funny Star Wars parody posted:

I didnt realize that you could specify intent class names using the .setClassName() meth
I straight up told you to do this :negative:

quote:

Thanks for this!

You're welcome

FAT32 SHAMER
Aug 16, 2012



Volmarias posted:

I straight up told you to do this :negative:


You're welcome

oh you did and i forgot to click the link :doh:

i'm literally retarded

Doh004
Apr 22, 2007

Mmmmm Donuts...
This might be the entirely wrong place, but is anyone here familiar with how to get in touch with any sort of Google Play Store category managers? Apple has a developer relations team and I was wondering if Google had something similar.

Taffer
Oct 15, 2010


Doh004 posted:

This might be the entirely wrong place, but is anyone here familiar with how to get in touch with any sort of Google Play Store category managers? Apple has a developer relations team and I was wondering if Google had something similar.

They categorically do not. They're famous for how much of a black box their store is, and getting in contact with someone to resolve issues is near-impossible.

Glimm
Jul 27, 2005

Time is only gonna pass you by

Doh004 posted:

This might be the entirely wrong place, but is anyone here familiar with how to get in touch with any sort of Google Play Store category managers? Apple has a developer relations team and I was wondering if Google had something similar.

Best I've done is post on Google+ and include prominent DevRel folks like Ian Lake in my post asking for help. This got me out or a jam once.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Contacting google customer support consists of getting a post on medium about your problem onto the front page of HN.

Adbot
ADBOT LOVES YOU

Doh004
Apr 22, 2007

Mmmmm Donuts...
Gotcha, that's more related to app support which is good to know - I'm actually asking about the business development people? Who manages the Play Store categories? How do you get featured more prominently? Set up partnerships between the two etc.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply