Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown for missing manufacturer when retrieving getDeviceName() #40

Open
RDLemos opened this issue Jul 11, 2020 · 4 comments
Open

Comments

@RDLemos
Copy link

RDLemos commented Jul 11, 2020

Hello,
I am using the library to retrieve the device market name, which works, but i always see this exception below for the missing manufacturer?

org.json.JSONException: No value for manufacturer
at org.json.JSONObject.get(JSONObject.java:389)
at org.json.JSONObject.getString(JSONObject.java:550)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.(DeviceName.java:374)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.(DeviceName.java:347)
at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111)
at com.atos.ucc.g3pten.core.services.G3PTenService.setDeviceInformation(G3PTenService.kt:307)
at com.atos.ucc.g3pten.core.services.G3PTenService.setup(G3PTenService.kt:143)
at com.atos.ucc.g3pten.core.services.G3PTenService.onCreate(G3PTenService.kt:100)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3522)
at android.app.ActivityThread.-wrap6(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1740)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6688)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

It is a very simple code:

I have initialized the lib:
DeviceName.init(this)

Then call:

    private fun setupDeviceInformation() {
        try {
            g3ptDeviceModelInformation =
                "${Build.MODEL} (${Build.MANUFACTURER}) (${DeviceName.getDeviceName()})"
            G3PTenLog.d(TAG, "[SVC] DeviceName: $g3ptDeviceModelInformation")
        } catch (e: Exception) {
            G3PTenLog.e(TAG, "[SVC] Error retrieving device name: $e")
            e.printStackTrace()
        }
    }
@andrewgrow
Copy link

andrewgrow commented Jul 20, 2020

I have the same trouble.
After I called:

/**
     * Will return a model of device(For example: Nexus 5)
     * @return String
     */
    public static String getDeviceModel() {
        if (Build.MODEL.equals(DeviceName.getDeviceName())) {
            return Build.MODEL;
        }
        return DeviceName.getDeviceName() + " (" + Build.MODEL + ")";
    }

Got error:

org.json.JSONException: No value for manufacturer
at org.json.JSONObject.get(JSONObject.java:400)
at org.json.JSONObject.getString(JSONObject.java:561)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:374)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:347)
at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111)

@Climax777
Copy link

Device: Xiaomi Redmi Note 8 Pro

W/System.err: org.json.JSONException: No value for manufacturer
W/System.err:     at org.json.JSONObject.get(JSONObject.java:399)
W/System.err:     at org.json.JSONObject.getString(JSONObject.java:560)
W/System.err:     at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:374)
W/System.err:     at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:347)
W/System.err:     at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186)
W/System.err:     at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138)
W/System.err:     at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111)
W/System.err:     ...
W/System.err:     at android.net.ConnectivityManager$NetworkCallback.onAvailable(ConnectivityManager.java:3
W/System.err:     at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
W/System.err:     at android.os.Looper.loop(Looper.java:224)
W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:67)

Same for me Samsung galaxy Note 9

@ilexbor
Copy link

ilexbor commented Jul 28, 2020

I am using AndroidDeviceNames library in the banking app and found a problem:
In the DeviceName class the getDeviceInfo() function uses the following code:

try {
  return new DeviceInfo(new JSONObject(savedJson));
}
catch (Exception e) {
  e.printStackTrace();
}

In this section of code, printStackTrace() outputs all exceptions to the console, even in the release build of the app. This behavior reduces the security of the application.
In addition, stack trace in the console always catches the eye and irritates.

If the library can perform its functions successfully without annoying stack trace in the console, then you don't need to output extra information to the console. If you need to get this information when developing the library, then it is better to run printStackTrace() in the library version only for the developers of the library itself. To do this, you can use Timber library or your custom logger.

Please fix the specified problem.

@C5FR7Q
Copy link

C5FR7Q commented Sep 24, 2020

Faced this too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants