class Jamf::MobileDevice

This class represents a Mobile Device stored in the JSS.


Adding devices to the JSS

When creating new MobileDevices in the JSS with this class (using {Jamf::MobileDevice.make}) you must specify a udid, and serial_number before calling ‘create` or `save`. You can provide these values with the `.make` call, or afterward using setters.


Management History & Logs

MobileDevice Management History and logs can now be retrieved both from a MobileDevice instance, and directly via class methods without fetching an instance. This is handled by the mixed-in {Jamf::ManagementHistory} module, Q.V. for details.


MDM Commands

See the {Jamf::MDM} mixin module for Class and Instance methods for sending MDM commands to mobiledevices.

To send MDM commands without fetching mobiledevice instances, use the class methods, which can take multiple identifiers at once.

NOTE: If the {#name=} method is used to change the name of a supervized device, the DeviceName MDM command will be sent to the device when the changes are sent to the server via {#save} or {#update}

Constants

HW_PREFIX_IPAD
HW_PREFIX_IPHONE
HW_PREFIX_TV
EXT_ATTRIB_CLASS

This is the class for relevant Extension Attributes

MDM_COMMAND_TARGET

What kind of devices are we for MDM purposes?

NON_UNIQUE_NAMES
OBJECT_HISTORY_OBJECT_TYPE

the object type for this object in the object history table. See {APIObject#add_object_history_entry}

OTHER_LOOKUP_KEYS

these keys, as well as :id and :name, can be used to look up objects of this class in the JSS the wierd alises wifi_mac_addresse, mac_addresse and macaddresse are for proper pluralization of ‘mac_address’ and such

RSRC_BASE

The base for REST resources of this class

RSRC_LIST_KEY

the hash key used for the JSON list output of all objects in the JSS

RSRC_OBJECT_KEY

The hash key used for the JSON object output. It’s also used in various error messages

SEARCH_CLASS

An AdvancedComputerSearch in the JSS

@see Jamf::AdvancedSearch

@see Jamf::APIObject

SITE_SUBSET

Where is the Site data in the API JSON?

UPLOAD_TYPES

file uploads can send attachments to the JSS using :mobiledevices as the sub-resource.

Attributes

airplay_password[R]

@return [String] the airplay passwd on devices that can receive AirPlay (i.e. apple tvs)

applications[R]

@return [Array<Hash>] the applications on the device

asset_tag[R]

@return [String]

available[R]

@return [Intger] how much space available on the device?

available_mb[R]

@return [Intger] how much space available on the device?

battery_level[R]

@return [Integer] what percentage of the battery is remaining

battery_percent[R]

@return [Integer] what percentage of the battery is remaining

ble_capable[R]

@return [Boolean] is this device ble_capable?

bluetooth_mac_address[R]

@return [String] the bluetooth mac addr

capacity[R]

@return [Integer] total storage on the device

capacity_mb[R]

@return [Integer] total storage on the device

certificates[R]

@return [Array<Hash>]

The certificates on the device

Each has has two keys:

  • :identity => Boolean

  • :common_name => String, possibly a udid

configuration_profiles[R]

@return [Array<Hash>]

One for each ConfigurationProfile on the device

The Hash keys are:

  • :identifier => a unique id, often the sams as the uuid

  • :display_name => its name in the JSS

  • :uuid => the ConfigurationProfile uuid

  • :version => a String

device_id[R]

@return [String] An Apple TV identifier

device_name[R]

@return [String]

device_ownership_level[R]

@return [String] the device_ownership_level

device_phone_number[R]

@return [String] the phone number of the device’s SIM card

display_name[R]

@return [String]

exchange_activesync_device_identifier[R]

@return [String]

initial_entry_date[R]

@return [Time] uses the value from the API’s initial_entry_date_epoch

ip_address[R]

@return [String] the IP addr

languages[R]

@return [String] the languages

last_backup[R]

@return [Time] uses the value from the API’s last_backup_time_epoch

last_backup_date[R]

@return [Time] uses the value from the API’s last_backup_time_epoch

last_backup_time[R]

@return [Time] uses the value from the API’s last_backup_time_epoch

last_cloud_backup_date[R]

@return [Time] last_cloud_backup_date

last_enrollment[R]

@return [Time] the last time this device enrolled in Jamf

last_inventory_update[R]

@return [Time] uses the value from the API’s last_inventory_update_utc

locales[R]

@return [String] the locales

managed[R]

@return [Boolean] is this device managed?

managed?[R]

@return [Boolean] is this device managed?

mobile_device_groups[R]

@return [Array<Hash>]

One for each group to which the device belongs

The Hash keys are:

  • :name => the group name

  • :id => the group id in the JSS

model[R]

@return [String] the display name of the model

model_display[R]

@return [String] the display name of the model

model_identifier[R]

@return [String] the model identifier

model_number[R]

@return [String] the display name of the model

modem_firmware[R]

@return [String] the model firmware

network[R]

@return [Hash]

A Hash of network data

The Hash keys are:

  • :voice_roaming_enabled=>“Disabled”,

  • :current_mobile_network_code=>“nnn”,

  • :imei=>“nn nnnnnn nnnnnn n”,

  • :home_mobile_country_code=>“nnn”,

  • :iccid=>“nnnn nnnn nnnn nnnn nnnn”,

  • :home_mobile_network_code=>“nnn”,

  • :current_carrier_network=>“”,

  • :data_roaming_enabled=>false,

  • :home_carrier_network=>“AT&T”,

  • :carrier_settings_version=>“16.0”,

  • :roaming=>false,

  • :cellular_technology=>“GSM”,

  • :current_mobile_country_code=>“nnn”

os_build[R]

@return [String] the OS build

os_type[R]

@return [String] the OS type

os_version[R]

@return [String] the OS version

percentage_used[R]

@return [Integer] how much of the capacity is in use?

provisioning_profiles[R]

@return [Array<Hash>]

One per provisioning profile

security[R]

@return [Hash]

A Hash of security data

The Hash has these keys, all of which are Boolean

  • :passcode_present=>true,

  • :passcode_compliant=>true,

  • :passcode_compliant_with_profile=>true,

  • :data_protection=>true,

  • :block_level_encryption_capable=>true,

  • :file_level_encryption_capable=>true

serial_number[R]

@return [String]

serialnumber[R]

@return [String]

shared[R]

@return [Boolean] is this device shared?

sim_phone_number[R]

@return [String] the phone number of the device’s SIM card

sn[R]

@return [String]

supervised[R]

@return [Boolean] is this device supervised?

supervised?[R]

@return [Boolean] is this device supervised?

tethered[R]

@return [String] the tether state of the device

udid[R]

@return [String]

wifi_mac_address[R]

@return [String] the wifi mac addr

Public Class Methods

all_managed(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all managed mobile devices

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
160 def self.all_managed(refresh = false, api: nil, cnx: Jamf.cnx)
161   cnx = api if api
162 
163   all(refresh, cnx: cnx).select { |d| d[:managed] }
164 end
all_unmanaged(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all unmanaged mobile devices

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
167 def self.all_unmanaged(refresh = false, api: nil, cnx: Jamf.cnx)
168   cnx = api if api
169 
170   all(refresh, cnx: cnx).reject { |d| d[:managed] }
171 end
new(**args) click to toggle source

@see APIObject#initialize

When creating new records with .make, udid:, serial_number:, and asset_tag: can be provided in the args.

Calls superclass method Jamf::APIObject::new
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
438 def initialize(**args)
439   super
440   if @in_jss
441 
442     gen = @init_data[:general]
443 
444     # identifiers
445     @serial_number = gen[:serial_number]
446     @udid = gen[:udid]
447     @asset_tag = gen[:asset_tag]
448     @device_id = gen[:device_id]
449     @device_name = gen[:device_name]
450     @display_name = gen[:display_name]
451     @exchange_activesync_device_identifier = gen[:exchange_activesync_device_identifier]
452 
453     # settings
454     @managed = gen[:managed]
455     @supervised = gen[:supervised]
456     @device_ownership_level = gen[:device_ownership_level]
457     @tethered = gen[:tethered]
458     @shared = gen[:shared]
459     @ble_capable = gen[:ble_capable]
460 
461     @airplay_password = gen[:airplay_password]
462     @languages = gen[:languages]
463     @locales = gen[:locales]
464 
465     # software
466     @os_type = gen[:os_type]
467     @os_build = gen[:os_build]
468     @os_version = gen[:os_version]
469     @modem_firmware = gen[:modem_firmware]
470 
471     # hardware
472     @model = gen[:model]
473     @model_number = gen[:model_number]
474     @model_identifier = gen[:model_identifier]
475     @model_display = gen[:model_display]
476 
477     # usage
478     @capacity_mb = gen[:capacity_mb]
479     @available_mb = gen[:available_mb]
480     @percentage_used = gen[:percentage_used]
481     @battery_level = gen[:battery_level]
482 
483     # network
484     @bluetooth_mac_address = gen[:bluetooth_mac_address]
485     @wifi_mac_address = gen[:wifi_mac_address]
486     @sim_phone_number = gen[:phone_number]
487     @ip_address = gen[:ip_address]
488 
489     # timestamps
490     @initial_entry_date = JSS.epoch_to_time gen[:initial_entry_date_epoch]
491     @last_backup_time = JSS.epoch_to_time gen[:last_backup_time_epoch]
492     @last_cloud_backup_date = JSS.epoch_to_time gen[:last_cloud_backup_date_epoch]
493     @last_inventory_update = JSS.epoch_to_time gen[:last_inventory_update_epoch]
494     @last_enrollment = JSS.epoch_to_time gen[:last_enrollment_epoch]
495 
496     # subsets
497     @mobile_device_groups = @init_data[:mobile_device_groups]
498     @network = @init_data[:network]
499     @extension_attributes = @init_data[:extension_attributes]
500     @certificates = @init_data[:certificates]
501     @configuration_profiles = @init_data[:configuration_profiles]
502     @provisioning_profiles = @init_data[:provisioning_profiles]
503     @security = @init_data[:security]
504     @applications = @init_data[:applications]
505   else
506     @udid = args[:udid]
507     @serial_number = args[:serial_number]
508     @asset_tag = args[:asset_tag]
509   end
510 end

Private Class Methods

all_apple_tvs(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all iPads

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
202 def self.all_apple_tvs(refresh = false, api: nil, cnx: Jamf.cnx)
203   cnx = api if api
204 
205   all(refresh, cnx: cnx).select { |d| d[:model_identifier].start_with? 'AppleTV' }
206 end
all_ipads(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all iPads

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
195 def self.all_ipads(refresh = false, api: nil, cnx: Jamf.cnx)
196   cnx = api if api
197 
198   all(refresh, cnx: cnx).select { |d| d[:model].start_with? 'iPad' }
199 end
all_iphones(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all iPhones

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
188 def self.all_iphones(refresh = false, api: nil, cnx: Jamf.cnx)
189   cnx = api if api
190 
191   all(refresh, cnx: cnx).select { |d| d[:model].start_with? 'iPhone' }
192 end
all_phone_numbers(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<String>] all mobiledevice phone numbers

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
153 def self.all_phone_numbers(refresh = false, api: nil, cnx: Jamf.cnx)
154   cnx = api if api
155 
156   all(refresh, cnx: cnx).map { |i| i[:phone_number] }.reject(&:empty?)
157 end
all_supervised(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all supervised mobile devices

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
174 def self.all_supervised(refresh = false, api: nil, cnx: Jamf.cnx)
175   cnx = api if api
176 
177   all(refresh, cnx: cnx).select { |d| d[:supervised] }
178 end
all_unsupervised(refresh = false, api: nil, cnx: Jamf.cnx) click to toggle source

@return [Array<Hash>] the list of all unsupervised mobile devices

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
181 def self.all_unsupervised(refresh = false, api: nil, cnx: Jamf.cnx)
182   cnx = api if api
183 
184   all(refresh, cnx: cnx).reject { |d| d[:supervised] }
185 end

Public Instance Methods

asset_tag=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
544 def asset_tag=(new_val)
545   new_val = new_val.strip
546   return nil if @asset_tag == new_val
547 
548   @asset_tag = new_val
549   @need_to_update = true
550 end
serial_number=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
530 def serial_number=(new_val)
531   return nil if new_val == @serial_number
532 
533   @serial_number =  new_val.empty? ? new_val : Jamf::Validate.doesnt_already_exist(self.class, :serial_number, new_val, cnx: cnx)
534   @need_to_update = true
535 end
udid=(new_val) click to toggle source
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
537 def udid=(new_val)
538   return nil if new_val == @udid
539 
540   @udid = new_val.empty? ? new_val : Jamf::Validate.doesnt_already_exist(self.class, :udid, new_val, cnx: cnx)
541   @need_to_update = true
542 end
update(no_mdm_rename: false) click to toggle source

@param no_mdm_rename should a MDM ‘set device name` command be sent

if the device is managed and supervised?
Calls superclass method Jamf::APIObject#update
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
554 def update(no_mdm_rename: false)
555   super()
556   return @id if no_mdm_rename || !@needs_mdm_name_change
557 
558   set_device_name @name if managed? && supervised?
559   @needs_mdm_name_change = false
560   @id
561 end

Private Instance Methods

apple_tv?()
Alias for: tv?
ipad?() click to toggle source
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
517 def ipad?
518   model_identifier.start_with? HW_PREFIX_IPAD
519 end
iphone?() click to toggle source
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
521 def iphone?
522   model_identifier.start_with? HW_PREFIX_IPHONE
523 end
name=(new_name) click to toggle source
Calls superclass method Jamf::Updatable#name=
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
525 def name=(new_name)
526   super
527   @needs_mdm_name_change = true if managed? && supervised?
528 end
rest_xml() click to toggle source

private methods

    # File lib/jamf/api/classic/api_objects/mobile_device.rb
568 def rest_xml
569   doc = REXML::Document.new Jamf::Connection::XML_HEADER
570   md = doc.add_element self.class::RSRC_OBJECT_KEY.to_s
571   general = md.add_element('general')
572   general.add_element('name').text = @name
573   general.add_element('udid').text = @udid
574   general.add_element('serial_number').text = @serial_number
575   general.add_element('asset_tag').text = @asset_tag
576 
577   md << ext_attr_xml if unsaved_eas?
578   md << location_xml if has_location?
579   md << purchasing_xml if has_purchasing?
580   add_site_to_xml doc
581   doc.to_s
582 end
tv?() click to toggle source
    # File lib/jamf/api/classic/api_objects/mobile_device.rb
512 def tv?
513   model_identifier.start_with? HW_PREFIX_TV
514 end
Also aliased as: apple_tv?