obtaining the user name of any user - android

I am currently using the following code to obtain the current user name:
String username;
{
Cursor c = ctx.getContentResolver().query(Profile.CONTENT_URI,
new String[]{Profile.DISPLAY_NAME}, null, null, null);
if (c.getCount() > 0)
{
c.moveToFirst();
username = c.getString(0);
}
On my test device (Samsung Galaxy Tab Pro), with the correct permissions, this works well for the "owner" user, as well as other non-restricted users. However, things seem to fall apart for limited user profiles:
The code always returns zero cursor rows. I had hoped that enabling access to the Contacts app would allow it to work, but that has no effect.
At any rate, unlike non-limited profiles, the profile of the limited user account does not seem to be connected to the name displayed on the lock screen, so even if I could get this code to work I'm not sure how useful it would be.
Please forgive the multi-part question, but:
Is this a peculiarity of the Samsung tablet, or is this behavior consistent across devices?
Is there any way to read the profile of a limited user?
Is there a better way to obtain the current user name?
Any insight appreciated.

I have tried to search about it & can say it's not possible to get details of "Restricted Profile (User)".
In background when you try to read details for "Restricted Profile user" they are trying to change in database and throw SQLiteexception : delete then re-write existing database throws SQLiteReadOnlyDatabaseException on getWritableDatabase. due to this exception I don't think there is chance to read user name.
Without use your above code you can get directly call getUsername() of UserManager class.[API Level 17]

Related

When using the AppCenter API for android Kotlin, Am I allowed to change my UserId multiple times in the same session

Sorry for the ambiguity in the question but it is actually quite a simple one.
When my android Application boots up I initialize AppCenter as follows:
AppCenter.start(
this, BuildConfig.APP_CENTER_SECRET,
Analytics::class.java, Crashes::class.java, Distribute::class.java
)
if(BuildConfig.FLAVOR != ApplicationVariants.ProductFlavors.PRODUCTION){
AppCenter.setLogLevel(Log.VERBOSE)
}
AppCenter.setUserId(UUID.randomUUID().toString())
Distribute.setUpdateTrack(UpdateTrack.PUBLIC)
Distribute.checkForUpdate()
However, when the user logs into the application I would like to set the UserId to the users email as follows once the user logs in:
JwtUtils.getIdentityTokenModel(requireContext())?.let {
AppCenter.setUserId(it.email)
}
Lastly when the user logs out I reset the user Id to a random guid. The reason for this is visibility on which user has which crash logs. This is a requirement from business.
However, in the app center crash logs, it seems the UserId never changes to the email even if an error occurs while the user is logged in.
My question is simple. Is there a restriction on how many times I am allowed to change the AppCenter User Id? I cannot seem to find it anywhere in the docs.
Thanks in advance
Please see these docs about userId API:
The value for the user ID is limited to 256 characters. It will be
shown with your crash reports but not used for aggregation or counts
of affected users. In case you set user ID multiple times, only the
last user ID will be used. You need to set the user ID yourself before
each application launch, because this value isn't stored by the SDK
between launches.

Google Credentials api with phone number verification

I am working on authentication procedure and the best that I found is this link. This matches to my app needs perfectaly.
But problem that I am facing is that , after doing described steps, I get a phone number picker dialog shown ad hidden and I get reply in onActivityResult callback as a canceld result and with empty data.
I do not know why that dialog closes it self not letting the user to choose the phone number and it returned it self in the OnActivityResult with canceled result code.
Please help me , I am stuck in it and I have no clue to go in that direction with.
I think its the problem of SIM. Some sim card allow this and some not. I will suggest you to do testing on real device. And change your sim card to ensure it must not be the carrier problem.
I have the same issue and then I changed SIM card and that codes start working for me. And that was really amazing to notice that it was not working from all sim cards. I am from India. Hope so it will be helpful for any Asian developer.
I have exactly same issue with this.
On some phone(even if it is brand new phone), phone number dialog is appeared and dismissed quickly.
And then credential id is returning null value.
onActivityResult
val credential: Credential? = data.getParcelableExtra(Credential.EXTRA_KEY)
var phoneNumber = credential?.id
if (phoneNumber == null) {
val tMgr = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
phoneNumber = tMgr.line1Number
}
I try to find a reason but failed. Instead, I use telephonyManager in this exceptional case. This is still not a good solution because user should see abnormal behavior and also should agree with phone permission. I also think this is related with SIM card.

Can an Android app be used to set the phone password?

I had an idea for an android security app, but looking over the Device Administrator api documentation, I can't see if it's even possible. I want the app to be able to set the password used to unlock the phone. It would need to set the password without input or confirmation from the user.
Anyone know if it's even possible, and if so, is there any documentation for it?
Found what I was looking for, it can be done per
http://developer.android.com/reference/android/app/admin/DevicePolicyManager.html#resetPassword(java.lang.String, int)
public boolean resetPassword (String password, int flags)
Added in API level 8
Force a new device unlock password (the password needed to access the entire device, not for individual accounts) on the user. This takes effect immediately. The given password must be sufficient for the current password quality and length constraints as returned by getPasswordQuality(ComponentName) and getPasswordMinimumLength(ComponentName); if it does not meet these constraints, then it will be rejected and false returned. Note that the password may be a stronger quality (containing alphanumeric characters when the requested quality is only numeric), in which case the currently active quality will be increased to match.
The calling device admin must have requested USES_POLICY_RESET_PASSWORD to be able to call this method; if it has not, a security exception will be thrown.
Parameters
password The new password for the user.
flags May be 0 or RESET_PASSWORD_REQUIRE_ENTRY.
Returns
Returns true if the password was applied, or false if it is not acceptable for the current constraints.
I dont think it is possible at all, since every app runs in kind of a sandbox to forbid for example malware executing something like you mentioned.
Looking at this: http://developer.android.com/guide/topics/admin/device-admin.html
There seems to be a way for an app to ask for a password:
Set a password for the device
This code displays a user interface prompting the user to set a password:
Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
startActivity(intent);
However, I'm not sure you can do this from within the app, silently without any user input. Also, Device Administration apps does not seem to be a normal apps and seem to be intended for corporations/institutions.

Banning By Mobile Device?

I am making some application that will be largely user driven and of course that means their will be trouble makers who probably will enter fake data into it using swear words or worse change valid data to bad data(ie changing to swear words)
Of course measures will be taken to try to curb this but in the end of the day I want to have the option to ban someone from my application.
My first thought is ban their account by email address. I was also thinking that maybe on top of that ban their devices.
My questions is is what unique id can I use from their phone if they use
Andriod
Iphone
Blackberry
Windows Phone 7/8
and how unique is it? Can it be easily changed?
For Windows Phone you should be able to use DeviceExtendedProperties. Specifically the DeviceUniqueId property.
Be aware though that, as they say in that article, if you use a device id to ban a user, then any future user of that same device will be banned from your app, even if they've done nothing wrong.
There are 2 identifiers that can be used together to identify a specific device and user.
The DeviceUniqueId and WindowsLiveAnonymousId
the first one is the device, and as noted, anyone who uses the device after the banned user will also be banned.
The WindowsLiveAnonymousId is unique to the user. I have seen this same identifier across 3 separate devices and it is always the same for the users LiveId.
I use the following 2 methods to get these ids for identifying game players for leader-boards:
//Note: to get a result requires ID_CAP_IDENTITY_DEVICE
// to be added to the capabilities of the WMAppManifest
// this will then warn users in marketplace
public static byte[] GetDeviceUniqueId()
{
byte[] result = null;
object uniqueId;
if (DeviceExtendedProperties.TryGetValue("DeviceUniqueId", out uniqueId))
result = (byte[])uniqueId;
return result;
}
// NOTE: to get a result requires ID_CAP_IDENTITY_USER
// to be added to the capabilities of the WMAppManifest
// this will then warn users in marketplace
public static string GetWindowsLiveAnonymousId()
{
string result = String.Empty;
object anid;
if (UserExtendedProperties.TryGetValue("ANID", out anid))
{
if (anid != null && anid.ToString().Length >= (AnidLength + AnidOffset))
{
result = anid.ToString().Substring(AnidOffset, AnidLength);
}
}
return result;
}
They are used as such:
string deviceUniqueId = String.Empty;
for (int i = 0; i < GetDeviceUniqueId().GetLength(0); i++)
{
deviceUniqueId += GetDeviceUniqueId().GetValue(i);
}
DeviceUniqueIDTextBlock.Text = deviceUniqueId;
WindowsLiveAnonymousIDTextBlock.Text = GetWindowsLiveAnonymousId().ToString(CultureInfo.InvariantCulture);
I did a post last May about getting system info on WP7. This code is found here: http://www.adambenoit.com/applications/system-info-windows-phone/
Hope this helps.
All these devices have network interfaces with unique MAC addresses which by definition are constant - the MAC address is burned into the hardware and cannot be [easily] spoofed, especially on a mobile device. I would hash the MAC address and use that as the key. Pretty common practice on iOS once apple banned the use of UDIDs.
I would use the guid method. Though this can be circumvented by uninstalling and re-installing the app. Nothings perfect though
How to create a GUID/UUID using the iPhone SDK
How to get GUID in android?
How to create a GUID on Windows Phone
http://msdn.microsoft.com/en-us/library/system.guid.newguid(v=vs.95).aspx
How to create a GUID on Blackberry http://supportforums.blackberry.com/t5/Java-Development/how-to-generate-GUID/td-p/289947

Android: Getting phone owner info

Since there is the permission called
android.permission.READ_OWNER_DATA
there MUST be a way to read the phone owner info on an android device.
The only thing I could find on the net is this:
Uri uri = Uri.withAppendedPath(Contacts.People.CONTENT_URI, "owner");
Cursor c = managedQuery(uri, null, null, null, null);
But 1) that doesn't work (owner path unknown) and 2) Contacts.People is deprecated (I guess this should now be ContactsContract.Contacts.CONTENT_URI)
I can't even get the mobile phone number of the device using the TelephonyManager (getLine1Number) ... even the built-in phoneinfo screen shows "unknown" for the phonenumber.
Anyway, seems like I can't figure it out on my own and can't find anything useful on the web either (except for the outdated (?) code above). Although I believe the above approach must be the right one (using some content provider that provides the owner info). There simply is no documentation about this except that Android provides the permission setting "android.permission.READ_OWNER_DATA" but no info about how to actually do that kind of thing.
Does anybody know how to get to the phone owner info (name, address, email, phone, ...) on Android? Thanks a mill!
(Background: Developing on Android SDK 2.1, Testing on Emulator and HTC Desire)
Android is open source. It seems, based on searching for READ_OWNER_DATA, that the "/people/owner" path in the contacts provider returns a cursor with some sort of owner information — assuming that information has been entered already by the user.
You'd have to double check the AOSP to see if that still applies for the newer contacts API.
this permission was removed
see :
http://developer.android.com/sdk/api_diff/9/changes/android.Manifest.permission.html

Categories

Resources