GPU Version, Renderer, Vendor in Android - android

I want to find GPU Vendor, its version and renderer.
I have used this code:-
renderer = GLES10.glGetString(GL10.GL_RENDERER);
vendor = GLES10.glGetString(GL10.GL_VENDOR);
version = GLES10.glGetString(GL10.GL_VERSION);
works on Android 4.3 and above, but when I ran this code on Android 2.3.6 it returns null.
However, the check following code check the GPUVersion which is returning "2.0" with 2.3.6:-
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
GPUVersion = configurationInfo.getGlEsVersion();
but still the above 3 lines returns null.
Is there any way to get the above information for all the devices.

Sometimes the only way to get a value across different Android versions is to split methods depending on which version you are running. You can do something like:
public static String getGlVersion(Context ctx) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ActivityManager am = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo configurationInfo = am.getDeviceConfigurationInfo();
return configurationInfo.getGlEsVersion();
} else {
return GLES10.glGetString(GLES10.GL_VERSION);
}
}
Be aware, though, that this might not work for all versions and you might need to split the method into more cases or change the min SDK_INT used for the comparison (I suspect for example that for Honeycomb it already needs the first method, but have not tested it).

Related

Is it safe to use the older getRefreshRate with the newer setFrameRate?

The new one without a "get": https://developer.android.com/reference/android/view/Surface#setFrameRate(float,%20int)
While Unreal Engine uses the older to get:
public int AndroidThunkJava_GetNativeDisplayRefreshRate()
{
if(ANDROID_BUILD_VERSION >= 24)
{
WindowManager windowManager = getWindowManager();
Display display = windowManager.getDefaultDisplay();
Display.Mode currentmode = display.getMode();
return (int)currentmode.getRefreshRate();
}
return 60;
}
For the most part, I'd think setFrameRate is provided as a smoother way to set, if no new get is provided, the old get should work.
This further convinces me:
https://android-developers.googleblog.com/2020/04/high-refresh-rate-rendering-on-android.html
"For this reason, applications may need to know the current device refresh rate. This can be done in the following ways:
SDK:
Registering a display listener with DisplayManager.DisplayListener and querying the refresh rate via Display.getRefreshRate
NDK
Registering a callback with AChoreographer_registerRefreshRateCallback (API level 30)"

How to detect programmatically if "Android App" is running in chrome book or in Android phone

Since Google has announced that chromebook also support "Android Application" so I also wanted to support my app on chromebook although it is running fine with few exception which I need to fix.
I want to write code in such a way that that is will execute only for chromebook and will not execute for android phones and tablet.
I have check with Chromebook documentation in android developer site, I didn't get any such API which tell that your app is running in chrome book environment.
Suggestion from ARC Beta documentation did not work:
If you need to check if your app is running on Chrome OS, look for chromium as the android.os.Build.BRAND and android.os.Build.MANUFACTURER.
Both return google on an ASUS Chromebook.
Finally I figure out a way to know if app in running in ARC:
context.getPackageManager().hasSystemFeature("org.chromium.arc.device_management");
Jan 15, 2023 Note-- Jump to the bottom of this answer to read how Google has changed their own method for checking YET AGAIN.
(Or keep reading for the history of the ARC check.)
Another method Google uses in their own code (updated several times now from link) is to check if Build.DEVICE ends with "_cheets". I don't know if ending device names like this is some kind of long-term strategy or a fast workaround, but it's also worth a look in addition to dex's proposed solution.
FWIW, since ARCWelder's method is deprecated and there's no official documentation on this (yet), I've also started a discussion in the XDA forums here for people to discuss what works/doesn't work on various devices.
Update 5/18: Looks like the code above was moved and updated, so Google's new ARC check as of May 2018 is here, particularly in this bit:
... } else if (Build.DEVICE != null && Build.DEVICE.matches(ARC_DEVICE_PATTERN)) {
mFormFactor = FORM_FACTOR_ARC;
} else { ...
where ARC_DEVICE_PATTERN is defined as
private static final String ARC_DEVICE_PATTERN = ".+_cheets|cheets_.+";
So it's not just a device ending with _cheets. It can start with cheets_ as well.
Update 8/26/20 -- As of 7 months ago, the source has been moved around from FormFactors.java to FeatureSupport.java. If you were looking for where it went- here it the code as of today.
public static boolean isArc() {
return (Build.DEVICE != null && Build.DEVICE.matches(".+_cheets|cheets_.+"));
}
The test remains the same.
Jan 15, 2023 -- The code has changed again! isArc() is now built into the FeatureUtil class (see commit here) The current version of isArc() :
/** Returns {#code true} if device is an ARC++ device. */
public static boolean isArc() {
return hasAnySystemFeature(ARC_FEATURE, ARC_DEVICE_MANAGEMENT_FEATURE);
}
Where ARC_FEATURE and ARC_DEVICE_MANAGEMENT_FEATURE are defined like this:
public static final String ARC_FEATURE = "org.chromium.arc";
public static final String ARC_DEVICE_MANAGEMENT_FEATURE = "org.chromium.arc.device_management";
the function hasAnySystemFeature() simply checks individual features and returns true if any is true.
Therefore the following might work as a simple standalone check in kotlin (where context is the activity context):
fun isArc(): Boolean {
return ((context.packageManager.hasSystemFeature("org.chromium.arc")) || (context.packageManager.hasSystemFeature("org.chromium.arc.device_management")))
Note this is similar to #dex's answer below, but includes both tests used by the Android source.
Incidentally, from looking at the code linked above you can also check other device characteristics like like isWatch(), isTV(), isAutomotive(), isPC(), isVrHeadset(), isLowRam(), etc. using similar feature checks.
PackageManager pm = context.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_PC))
// it's a chromebook
I found the solution in Android CTS code.
public static boolean isArc(#NonNull Context context) {
PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature( "org.chromium.arc" ) || pm.hasSystemFeature( "org.chromium.arc.device_management" );
}

Settings.Secure.ALLOW_MOCK_LOCATION always returns 1 even mock setting is Off

I'm developing an app where a user will not be able to use it if mock location setting is enabled using this piece of code
if (Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ALLOW_MOCK_LOCATION).equals("0"))
return false;
else
return true;
well it was working fine in most of my test devices from KitKat to Marshmallow systems, until I tried my app on this single device with Marshmallow OS, the mock setting is clearly OFF, but that code above keeps telling me that the mock setting is ON, is this a bug? or am i missing something here?
Checking out this answer from here.
boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
isMock = location.isFromMockProvider();
} else {
isMock = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}
This might help you
According to the android developer reference: https://developer.android.com/reference/android/provider/Settings.Secure.html ALLOW_MOCK_LOCATION is now deprecated in SDK 23.
The default value you will get will always be 1 in marshmallow.

What functions or codes require GET_TASKS permission in Android?

I think the GET_TASKS permission is an orphan line in my AndroidManifest.xml. I want to remove it safely. Do you know any function or code that requires this permission? Thank you.
<uses-permission android:name="android.permission.GET_TASKS" />
From the android reference
Allows an application to get information about the currently or
recently running tasks.
An example is public List<ActivityManager.RecentTaskInfo> getRecentTasks (int maxNum, int flags) as it throws SecurityException if the caller does not hold the GET_TASKS permission.
Note that according to the documentation
This constant was deprecated in API level 21. No longer enforced.
and
As of LOLLIPOP, this method is no longer available to third party
applications: the introduction of document-centric recents means it
can leak personal information to the caller. For backwards
compatibility, it will still return a small subset of its data: at
least the caller's own tasks (though see getAppTasks() for the correct
supported way to retrieve that information), and possibly some other
tasks such as home that are known to not be sensitive.
class CheckRunningActivity extends Thread{
ActivityManager am = null;
Context context = null;
public CheckRunningActivity(Context con){
context = con;
am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
}
public void run(){
Looper.prepare();
while(true){
// Return a list of the tasks that are currently running,
// with the most recent being first and older ones after in order.
// Taken 1 inside getRunningTasks method means want to take only
// top activity from stack and forgot the olders.
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1);
String currentRunningActivityName = taskInfo.get(0).topActivity.getClassName();
if (currentRunningActivityName.equals("PACKAGE_NAME.ACTIVITY_NAME")) {
// show your activity here on top of PACKAGE_NAME.ACTIVITY_NAME
}
}
Looper.loop();
}
}

Check Android build project target API level at runtime [duplicate]

This question already has answers here:
Programmatically obtain the Android API level of a device?
(7 answers)
Closed 8 years ago.
I have an application, and it behaves differently when I run it on API 18 or 19. This is not a problem, and I know why does it happen.
However, I want to write one code that will deal with both the versions.
Is there any way to get in runtime which API my application was built with? Specifically, I would like to get 18 or 19 if I build my application with these APIs.
EDIT
It seems to be a duplicate question. I thought that the BUILD_VERSION is something else, because, when I compiled both the versions to API 18 and 19, and print the version, I receive 18. It looks like another problem (although I specified API 19, it is compiled according to 18).
I found that the problem was in the emulator configurations.
I didn't understand your problem completely. But if you want to check which Build Version your app is working on and then act accordingly the you can use the following.
if(Build.VERSION.SDK_INT == 18 ){
// Do some stuff
}
else if (Build.VERSION.SDK_INT == 19) {
// Do some stuff
}
else{
// Do some stuff
}
The Android docs provides some sample code of how to load bitmaps effectively that handles this problem.
The code defines static methods in a class Utils that it references when it needs to know what platform the app is running on. The benefit of doing this is that you can reuse the function calls rather than rewriting long conditional statements over and over. The code looks like this:
public static boolean hasFroyo() {
// Can use static final constants like FROYO, declared in later versions
// of the OS since they are inlined at compile time. This is guaranteed behavior.
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
}
public static boolean hasGingerbread() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
}
public static boolean hasHoneycomb() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
}
public static boolean hasHoneycombMR1() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1;
}
public static boolean hasJellyBean() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
}
public static boolean hasKitKat() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
android.os.Build.VERSION.SDK_INT
Check this link out
Build Version Codes
So you can use as follows...
int thisDevicesApi =Build.VERSION.SDK_INT;
if (thisDevicesApi <=Build.VERSION_CODES.GINGERBREAD) {
//for example
//do something
}

Categories

Resources