Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:08:27+00:00 2026-06-18T04:08:27+00:00

I’ll apologize in advance for posting alot of code, this issue has really got

  • 0

I’ll apologize in advance for posting alot of code, this issue has really got me!

I have two Android JUnit tests that are causing me problems. Run each individually and they work fine, but when run together in one go (PasswordEntryActivityTests and then CryptoKeystoreTests) CryptoKeystoreTests hangs indefinitely.

I know it’s not just the emulator being slow because each individually finishes in less than a second but it can hang for more than 20 minutes. I also tested it on a real device (Droid Razr) and it does the same thing.

The problematic code is the PasswordEntryActivity.launchNewPasswordActivity(). Removing that function makes everything work fine.

Pausing the function in the debugger while it’s hanging says it’s in:

MessageQueue.nativePollOnce(int, int) line: not available [native method]

What’s going on?

I’ve copied below:

  • PasswordEntryActivity
  • PasswordEntryActivityTests
  • CryptoManagerKeystoreTests

Please let me know to post any other code you’d like to see.
Thanks!

    public class PasswordEntryActivity extends Activity 
    {
...
        private void launchNewPasswordActivity()
        {
            Intent launchNewPasswordIntent = new Intent(this, NewPasswordActivity.class);
            startActivity(launchNewPasswordIntent);
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.password_entry_layout);
...
            //this code should be LAST in onCreate because it exits the Activity
            //CryptoManager.passwordIsRight returns 0 if no password has been set
            passwordExists = CryptoManager.passwordIsRight("x", this) != 0;
            if(!passwordExists)
                launchNewPasswordActivity();
        }
    }

That Activity’s test:

    //supposed to make sure the application responds correctly when no password is set
    public class PasswordEntryActivityTests extends android.test.ActivityInstrumentationTestCase2<                          crypnote.controller.main.PasswordEntryActivity>{
    protected void setUp() throws Exception 
    {
        passwordEntryActivity = getActivity();

        //delete the database if it exists
        File file = passwordEntryActivity.getFileStreamPath(DBInterface.Constants.DatabaseName);
        if(file.exists())
            assertTrue(file.delete());
        file = passwordEntryActivity.getFileStreamPath(CryptoManager.Constants.KEYSTORE_PATH);
        if(file.exists())
            assertTrue(file.delete());
    }
    //allows us to access the interface
    @UiThreadTest
    public void testNoPassword() throws Exception
    {
        passwordEntryActivity  = getActivity();

        EditText passwordEntryEditText = 
                (EditText) passwordEntryActivity.findViewById(
                crypnote.controller.main.R.id.passwordentrylayout_passwordedittext);
        Button unlockButton = (Button) passwordEntryActivity.findViewById(
                                        crypnote.controller.main.R.id.passwordentrylayout_unlockbutton);


        int passwordResult = CryptoManager.passwordIsRight("x", getActivity());
        assertTrue(passwordResult == 0);

        //pass a wrong password to the edittext and click the unlock button
        passwordEntryEditText.setText("x");
        assertTrue(unlockButton.performClick());

        //get the foreground activity class name
        ActivityManager am = (ActivityManager) passwordEntryActivity.
                                                        getSystemService(Context.ACTIVITY_SERVICE);

        // get the info from the currently running task
        List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1); 

        ComponentName componentInfo = taskInfo.get(0).topActivity;
        String foregroundClassName = componentInfo.getShortClassName();

        //don't forget the leading '.'
        assertTrue(!foregroundClassName.equals(".PasswordEntryActivity"));
    }
}

The CryptoKeystoreTests:

public class CryptoKeystoreTests extends android.test.ActivityInstrumentationTestCase2<
                                                                crypnote.controller.main.PasswordEntryActivity>
{
    public void testKeystore() throws Exception
    {
        Context context = getActivity();

        //delete the database if it exists
        File file = context.getFileStreamPath(DBInterface.Constants.DatabaseName);
        if(file.exists())
            assertTrue(file.delete());
        file = context.getFileStreamPath(CryptoManager.Constants.KEYSTORE_PATH);
        if(file.exists())
            assertTrue(file.delete());

        CryptoManager cryptoManager=null;
        String password = CryptoManager.Constants.DEBUG_PASSWORD;
        FileInputStream fis=null;

            //the cryptomanager will generate a new key and keystore
            cryptoManager = new CryptoManager(password, context);
            Key CRYPTOKEY = cryptoManager.getKey();
            cryptoManager.close();

            //initialize KeyStore
            KeyStore keystore = KeyStore.getInstance(Constants.KEYSTORE_INSTANCE_TYPE);
            fis = context.openFileInput(CryptoManager.Constants.KEYSTORE_PATH);
            keystore.load(fis, password.toCharArray());

            assertTrue(keystore.containsAlias(Constants.APP_ALIAS));    
            assertTrue(keystore.isKeyEntry(Constants.APP_ALIAS));

            Key key = keystore.getKey(CryptoManager.Constants.APP_ALIAS, 
                                        password.toCharArray());
            assertTrue(key.getAlgorithm().equals(CryptoManager.Constants.PROVIDER_NAME));

            assertTrue(key.getAlgorithm().equals(CRYPTOKEY.getAlgorithm()));
            assertTrue(key.getFormat().equals(CRYPTOKEY.getFormat()));

            if(fis != null)
                fis.close();
    }
}

EDIT: NewPasswordActivity.onCreate:

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.new_password_layout);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:08:29+00:00Added an answer on June 18, 2026 at 4:08 am

    It hangs because PasswordEntryActivityTests does not release/finish the resources/UI events that has been addressed/created by itself during its own running lifecycle, more specifically, then newly opened NewPasswordActivity.

    PasswordEntryActivityTests starts by testing a creation of PasswordEntryActivity, i.e. getActivity(), which in consequence, based on the condition, launch a second NewPasswordActivity, the newly opened NewPasswordActivity occupy the foreground window and stay forever, it is developer’s responsibility to release it properly after you have done your testing.

    In instrumentation test, the correct way of detecting/monitoring second activity startup from current activity is to use ActivityMonitor, see the pseudo code below:

    // No password result starting a second activity.
    public void testNoPassword() {
      // register NewPasswordActivity that need to be monitored.
      ActivityMonitor activityMonitor = getInstrumentation().addMonitor(NewPasswordActivity.class.getName(), null, false);
    
      // Get current activity, it will start NewPasswordActivity in consequence.
      PasswordEntryActivity currentActivity = getActivity();
    
      NewPasswordActivity nextActivity = getInstrumentation().waitForMonitorWithTimeout(activityMonitor, 5);
      // NewPasswordActivity is opened and captured.
      assertNotNull(nextActivity);
      // Don't forget to release/finish NewPasswordActivity after test finish.
      nextActivity.finish();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.